forked from gavrilaf/MiniTerm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
143 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Foundation | ||
|
||
class CommandProcessor { | ||
|
||
func run(command: String, with stdout: StreamWriter) { | ||
stdout.Write(string: "\(command): command not found!") | ||
} | ||
} |
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,40 @@ | ||
import Foundation | ||
|
||
class InteractionHandler: InteractionHandlerProtocol { | ||
|
||
weak var updateDelegate: ScreenBufferUpdateDelegate? | ||
|
||
func symbol(_ c: String) { | ||
screenBuffer.addChar(c) | ||
updateDelegate?.didScreenUpdate(with: screenBuffer) | ||
} | ||
|
||
func delete() { | ||
screenBuffer.delete() | ||
updateDelegate?.didScreenUpdate(with: screenBuffer) | ||
} | ||
|
||
func newLine() { | ||
let command = screenBuffer.currentLine | ||
|
||
screenBuffer.Open() | ||
commandProcessor.run(command: command, with: screenBuffer) | ||
screenBuffer.Close() | ||
|
||
updateDelegate?.didScreenUpdate(with: screenBuffer) | ||
} | ||
|
||
func start() { | ||
updateDelegate?.didScreenUpdate(with: screenBuffer) | ||
} | ||
|
||
init() { | ||
screenBuffer = ScreenBuffer() | ||
commandProcessor = CommandProcessor() | ||
} | ||
|
||
// MARK: - private | ||
|
||
private let screenBuffer: ScreenBuffer | ||
private let commandProcessor: CommandProcessor | ||
} |
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,13 @@ | ||
import Foundation | ||
|
||
protocol InteractionHandlerProtocol { | ||
|
||
func start() | ||
|
||
func symbol(_ c: String) | ||
func delete() | ||
func newLine() | ||
|
||
var updateDelegate: ScreenBufferUpdateDelegate? { get set } | ||
} | ||
|
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,9 @@ | ||
import Foundation | ||
|
||
protocol ScreenBufferProtocol { | ||
var content: String { get } | ||
} | ||
|
||
protocol ScreenBufferUpdateDelegate: class { | ||
func didScreenUpdate(with buffer: ScreenBufferProtocol) | ||
} |
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,9 @@ | ||
import Foundation | ||
|
||
|
||
protocol StreamWriter { | ||
func Open() | ||
func Close() | ||
|
||
func Write(string: String) | ||
} |
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