SSH Terminal View Controller - TJohn2017/Laputa GitHub Wiki

SSHTerminalViewController.swift

makeFrame (keyboardDelta: CGFloat, keyboardWillHide: Bool)

Creates a new view frame for when the keyboard appears or disappears from the terminal view.

updateTerminalFrame(splitHeight: CGFloat)

Updates the terminal frame when in split view. When the slider in session page view resizes the terminal view, the SSHTerminalViewController update function gets called, and that is when we call this function to update the split screen height of the terminal to the value passed down from session page view.

startSSHSession()

Starts a new SSH session and checks if the connection is connected.

addKeyboard()

Adds keyboard notifications for when the keyboard appears and disappears.

handleKeyboardWillHide()

Called when the keyboard disappears from the screen. Remakes terminal view frame to grow and fill the screen using makeFrame.

keyboardNotification(_ notification: NSNotification)

Called when the keyboard appears on the screen. Remakes terminal view frame to shrink so that it sits right above the keyboard. It was important to resize the terminal view frame so that the user can see the very last line of the terminal when typing. The default state of the keyboard did not recognize the terminal view as a input text field so it would usually cover the terminal view.

viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)

Override func. Called when rotating screen from landscape to portrait mode and vice versa. Resizes the terminal view and the button on top of the terminal view to fit the screen.

loadView()

Override func. Called once when the view first gets initialized.

viewDidLoad()

Override func. Called once after view first loads. Initializes the keyboard button, catch output button, pan gesture recognizer, and error view if the ssh connection failed.

initializeKeyboardButton(t: TerminalView)

Initializes the keyboard button that when pressed, will bring up the keyboard. When the keyboard is up, the button will disappear from the view.

showKeyboard()

Brings up the keyboard in the view.

initializeOutputCatchButton(t: TerminalView)

Initializes the output catch button. When pressed, it will trigger output catching mode so that the user can highlight any text from the terminal.

toggleOutputCatching()

Toggles output catching mode. When true, user can highlight text from terminal and save to a code card on a canvas.

saveContentToCodeCard(content: String)

Given a string of highlighted text from the terminal, we make a new codeCard and save it to CoreData.

getStartEndRowIndex (startPoint: CGPoint, translation: CGPoint, rows: Int)

Given the starting point and ending point of the pan gesture, computes the start and end row index of the terminal. The terminal view is broken down into lines. SwiftTerm provides a function called getLine which will return the text of the line number given in the terminal.

didPan(_ sender: UIPanGestureRecognizer)

Called when pan gesture is recognized. If in output catching mode, panning over the terminal view will high the lines of the terminal that will appear in the code card. SwiftTerm does not provide a text highlight function for ios apps. Thus, using the start and end points of the pan gesture, we create a transparent rectangle that changes size in real time to show the user the lines that are selected. If not in output catching mode, then panning up and down the terminal view will scroll the view. Scrolling is accomplished by using SwiftTerms provided api functions scrollDown(lines: int) and scrollUp(lines: int).

generateErrorView()

Generates an error view that will tell the user they were unable to connect to the desired host.