Skip to content
This repository was archived by the owner on Jan 6, 2026. It is now read-only.
This repository was archived by the owner on Jan 6, 2026. It is now read-only.

Add final features #22

Description

@skippyr

I've finally decided that Teco will be a macOS-specific framework that will support both line-oriented and screen-oriented apps, but only a limited set of terminal events, on its own way.

This issue tracks the addition of the final features I plan to add to the framework, which were previously being discussed in #17, #15, and #4.

Furthermore, I am already rewriting the documentation to be fully integrated within Xcode (#21).

Those features are:

// Cursor Manipulation Functions
// Moves the cursor to a specific coordinate.
try! Terminal.moveCursor(to: .init(column: 0, row: 0))
try! Terminal.moveCursor(column: 0, row: 0)

// Moves the cursor in a direction by a given number of steps.
try! Terminal.moveCursor(.right, by: 5)

// Obtains the current cursor coordinate.
let cursorCoordinate = try! Terminal.cursorCoordinate
Terminal.print("Cursor Coordinate: (column: \(cursorCoordinate.column), row: \(cursorCoordinate.row))")

// ---

// Signal Handling Function
// Sets the given signal handler, possibly injecting code to reset active terminal properties.
Terminal.attachSignalHandler(for: .sigint) {
    Terminal.print("Interrupt Signal")
}

// ---

// Event Reading Functions (only for screen resize and key events)
// Clear cached events from the input buffer.
Terminal.clearEventQueue()

// Pulls the next cached key event.
// Screen resize events are errors that need to be catched, so you don't need to unwrap an enum to filter keys.
Terminal.print("Press \("[Escape]".red.bold) to cancel...")
do {
    let key = try Terminal.pullKeyEvent(waitFor: .seconds(2)) { $0 == .escape }
    guard key == nil else {
        Terminal.print("Operation Cancelled".red, via: .error)
    }
} catch Terminal.Error.screenResizeInterrupt {
    Terminal.print("Screen has been resized. Redrawing interface...")
} catch Terminal.Error.timerElapsed {
    Terminal.print("Timer has been elapsed. Continuing operation.")
}

// ---
// Convenient Input Functions
// Default values are optionals.

// Reads a line of input, similar to Swift's readLine function.
// Outputs: What is the name of your project? (default: My Project)
_ = try! Terminal.readLineQuestion("What is the name of your project?", default: "My Project")
// Reads the "Y" or "N" key input.
// Outputs: Do you want to proceed with the installation? (Y/n)
_ = try! Terminal.readYesOrNoQuestion("Do you want to proceed with the installation?", default: true)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions