Skip to content

Commit

Permalink
Continue work on supporting URL payloads in the terminal. Needs to … (#…
Browse files Browse the repository at this point in the history
…64)

* Continue work on supporting URL payloads in the terminal.   Needs to likely highlight the whole line before it is useful, some touchups on the font sizes and color for the hovers, and compare visually to iTerm

* Fix after merge

* Complete the url handling, fixed various pending bugs
  • Loading branch information
migueldeicaza authored Apr 12, 2020
1 parent 22e7a52 commit f1b0a74
Show file tree
Hide file tree
Showing 5 changed files with 386 additions and 90 deletions.
1 change: 0 additions & 1 deletion MacTerminal/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import SwiftTerm
class ViewController: NSViewController, LocalProcessTerminalViewDelegate, NSUserInterfaceValidations {
@IBOutlet var loggingMenuItem: NSMenuItem?


var changingSize = false
var logging: Bool = false

Expand Down
70 changes: 68 additions & 2 deletions SwiftTerm/Sources/SwiftTerm/CharData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,45 @@ public struct Attribute: Equatable, Hashable {
}
}

/// TinyAtoms are 16-bit values that can be used to represent a string as a number
/// you create them by calling TinyAtom.lookup (String) and retrieve the
/// value using the `target` property. They are used to store the urls and any
/// additional parameter information in the OSC 8 scenario.
///
/// This is kept to 16 bits for now, so that we keep the CharData to less than 15 bytes
/// it could in theory be changed to be 24 bits without much trouble
public struct TinyAtom {
var code: UInt16
static var stringMap: [UInt16:String] = [:]
static var lastUsed: Int = 0
static var empty = TinyAtom (code: 0)

private init(code: UInt16)
{
self.code = code
}

/// Returns the TinyAtom associated with the specified url, or nil if we ran out of space
public static func lookup (text: String) -> TinyAtom? {
let next = lastUsed + 1
if next < UInt16.max {
stringMap [UInt16 (next)] = text
lastUsed = next
return TinyAtom (code: UInt16 (next))
}
return nil
}

/// Returns the target for the TinyAtom
public var target: String? {
get {
if code == 0 {
return nil
}
return TinyAtom.stringMap [code]
}
}
}
/**
* Stores a cell with both the character being displayed as well as the color attribute.
* This uses an Int32 to store the value, if the value can not be encoded as a single Unicode.Scalar,
Expand All @@ -169,15 +208,21 @@ public struct CharData {
// Contains the index to character mapping, could be a plain array
static var indexToCharMap: [Int32: Character] = [:]
static var lastCharIndex: Int32 = (1 << 22)+1



public static let defaultAttr = Attribute(fg: .defaultColor, bg: .defaultColor, style: .none)
public static let invertedAttr = Attribute(fg: .defaultInvertedColor, bg: .defaultInvertedColor, style: .none)

// Contains a rune, or a pointer into a Grapheme Cluster
var code: Int32

///Contains the number of columns used by the `Character` stored in this `CharData` on the screen.
public var width: Int8
public private(set) var width: Int8

// This contains an assigned key
var urlPayload: TinyAtom

var unused: UInt8 // Purely here to align to 16 bytes

/// The color and character attributes for the cell
public var attribute: Attribute
Expand All @@ -202,6 +247,8 @@ public struct CharData {
}
}
width = Int8 (size)
urlPayload = TinyAtom.empty
unused = 0
}

// Empty cell sets the code to zero
Expand All @@ -210,6 +257,8 @@ public struct CharData {
self.attribute = attribute
code = 0
width = 1
urlPayload = TinyAtom.empty
unused = 0
}

public var isSimpleRune: Bool {
Expand All @@ -218,6 +267,23 @@ public struct CharData {
}
}

/// Sets the Url token for the this CharData.
mutating public func setUrlPayload (atom: TinyAtom)
{
self.urlPayload = atom
}

public func getPayload () -> String?
{
urlPayload.target
}

public var hasUrl: Bool {
get {
return urlPayload.code != 0
}
}

/// The `Null` character can be used when filling up parts of the screeb
public static var Null : CharData = CharData (attribute: defaultAttr)

Expand Down
Loading

0 comments on commit f1b0a74

Please sign in to comment.