-
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
1 parent
0890b8f
commit 5d340a5
Showing
4 changed files
with
69 additions
and
21 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,59 @@ | ||
// | ||
// Terminal.swift | ||
// | ||
// | ||
// Created by Aaron Jones on 4/28/23. | ||
// | ||
|
||
import Foundation | ||
|
||
enum TerminalType: String { | ||
case dumb = "dumb" | ||
case xterm = "xterm" | ||
case file = "file" | ||
case other = "other" | ||
} | ||
|
||
struct Terminal { | ||
var name: String | ||
var type: TerminalType | ||
|
||
var colors: Int { | ||
switch self.name { | ||
case "xterm": | ||
return 8 | ||
case "xterm-16color": | ||
return 16 | ||
case "xterm-256color": | ||
return 256 | ||
default: | ||
return 0 | ||
} | ||
} | ||
|
||
var columns: Int { | ||
if let colStr = ProcessInfo.processInfo.environment["COLUMNS"] { | ||
if let colInt: Int = Int(colStr) { | ||
return colInt | ||
} | ||
} | ||
|
||
return 80 | ||
} | ||
|
||
init() { | ||
if let term = ProcessInfo.processInfo.environment["TERM"]?.lowercased().trimmingCharacters(in: .whitespacesAndNewlines) { | ||
self.name = term.isEmpty ? "dumb" : term | ||
if term.isEmpty || ["dumb", "cons25", "emacs"].contains(term) { | ||
self.type = .dumb | ||
} else if term.contains("xterm") { | ||
self.type = .xterm | ||
} else { | ||
self.type = .other | ||
} | ||
} else { | ||
self.name = "dumb" | ||
self.type = .dumb | ||
} | ||
} | ||
} |