-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor code to allow other terminal implementations.
Introduce Terminal Interface to the File Browser shell commands.
- Loading branch information
Showing
4 changed files
with
104 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
Class { | ||
#name : 'StTerminalInterface', | ||
#superclass : 'Object', | ||
#classVars : [ | ||
'Default' | ||
], | ||
#category : 'NewTools-FileBrowser-Utilities', | ||
#package : 'NewTools-FileBrowser', | ||
#tag : 'Utilities' | ||
} | ||
|
||
{ #category : 'instance creation' } | ||
StTerminalInterface class >> default [ | ||
|
||
^ Default | ||
ifNil: [ Default := self new ] | ||
] | ||
|
||
{ #category : 'accessing' } | ||
StTerminalInterface class >> default: aClass [ | ||
|
||
Default := aClass | ||
] | ||
|
||
{ #category : 'accessing' } | ||
StTerminalInterface >> openLinuxTerminalShellCommand: aPath [ | ||
|
||
^ String streamContents: [ : stream | | ||
stream | ||
<< 'gnome-terminal --working-directory='; | ||
<< aPath fullName; | ||
<< ' &' ] | ||
] | ||
|
||
{ #category : 'accessing' } | ||
StTerminalInterface >> openMacTerminalShellCommand: aPath [ | ||
|
||
| escaped | | ||
escaped := aPath fullName copyReplaceAll: ' ' with: '\ '. | ||
^ String streamContents: [ : stream | | ||
stream | ||
<< 'open -a '; | ||
<< self preferredMacTerminalProgram; | ||
space; | ||
<< escaped; | ||
<< ' &' ] | ||
] | ||
|
||
{ #category : 'accessing' } | ||
StTerminalInterface >> openTerminalOn: aPath [ | ||
|
||
(self terminalShellCommand: aPath) | ||
ifNotEmpty: [ : shellCmd | | ||
(Delay forMilliseconds: 1000) wait. | ||
LibC system: shellCmd ] | ||
] | ||
|
||
{ #category : 'accessing' } | ||
StTerminalInterface >> openWindowsTerminalCommand: aPath [ | ||
|
||
^ String streamContents: [ : stream | | ||
stream | ||
<< 'start cmd.exe /K "cd /d '; | ||
<< aPath fullName; | ||
<< '"' ] | ||
] | ||
|
||
{ #category : 'accessing' } | ||
StTerminalInterface >> preferredMacTerminalProgram [ | ||
|
||
^ StFileBrowserSettings macTerminalProgram | ||
|
||
] | ||
|
||
{ #category : 'accessing' } | ||
StTerminalInterface >> terminalShellCommand: aPath [ | ||
"Answer a <String> with the shell command to open a terminal for the receiver's OS" | ||
|
||
Smalltalk os isWindows | ||
ifTrue: [ ^ self openWindowsTerminalCommand: aPath ]. | ||
Smalltalk os isMacOS | ||
ifTrue: [ ^ self openMacTerminalShellCommand: aPath ]. | ||
(Smalltalk os version beginsWith: 'linux') | ||
ifTrue: [ ^ self openLinuxTerminalShellCommand: aPath ]. | ||
|
||
self inform: 'No terminal for platform implemented'. | ||
^ String empty. | ||
] |