Skip to content

Commit

Permalink
Cleaned up code
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Feb 28, 2024
1 parent 5d3564c commit bc41ecc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
18 changes: 11 additions & 7 deletions src/core/screen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ import hypotenuse.*
import scala.compiletime.*

case class PtyState
(cursor: Int = 0, savedCursor: Int = 0, style: Style = Style(), focusDetectionMode: Boolean = false,
focus: Boolean = true, bracketedPasteMode: Boolean = false, hideCursor: Boolean = false,
title: Text = t"", link: Text = t"")
(cursor: Int = 0,
savedCursor: Int = 0,
style: Style = Style(),
focusDetectionMode: Boolean = false,
focus: Boolean = true,
bracketedPasteMode: Boolean = false,
hideCursor: Boolean = false,
title: Text = t"",
link: Text = t"")

object Pty:
def apply(width: Int, height: Int): Pty = Pty(ScreenBuffer(width, height), PtyState(), Funnel())
Expand All @@ -45,7 +51,6 @@ object Pty:
case _ => LazyList()

object PtyEscapeError:

object Reason:
given communicable: Communicable[Reason] =
case BadSgrParameters(ns) => msg"${ns} is not a valid SGR parameter sequence"
Expand Down Expand Up @@ -149,7 +154,6 @@ case class Pty(buffer: ScreenBuffer, state0: PtyState, output: Funnel[Text]):

def title(text: Text): Unit = state = state.copy(title = text)
def setLink(text: Text): Unit = link = text

def su(n: Int): Unit = buffer2.scroll(n)
def sd(n: Int): Unit = buffer2.scroll(-n)
def hvp(n: Int, m: Int): Unit = cup(n, m)
Expand Down Expand Up @@ -257,8 +261,7 @@ case class Pty(buffer: ScreenBuffer, state0: PtyState, output: Funnel[Text]):
case _ => throw Panic(msg"tried to access non-existent palette color")

def color8(n: Int): Rgb24 = n match
case n if 0 <= n <= 15 =>
palette(n)
case n if 0 <= n <= 15 => palette(n)

case n if 232 <= n <= 255 =>
val gray = n - 232
Expand Down Expand Up @@ -309,6 +312,7 @@ case class Pty(buffer: ScreenBuffer, state0: PtyState, output: Funnel[Text]):
then Pty(buffer2, state.copy(cursor = cursor(), style = style, link = link), output = output)
else
val current: Char = unsafely(input(index))

context match
case Normal => (current: @switch) match
case '\u0000' => proceed(Normal) // nul()
Expand Down
29 changes: 14 additions & 15 deletions src/core/yossarian.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ object Yossarian:
def render: Text = String(charBuffer).grouped(width).to(List).map(_.tt).join(t"\n")

def find(text: Text): Optional[ScreenBuffer] = line.render.s.indexOf(text.s) match
case -1 =>
Unset
case -1 => Unset

case index =>
(text.length, styleBuffer.slice(index, index + text.length),
charBuffer.slice(index, index + text.length), linkBuffer.slice(index, index + text.length))
charBuffer.slice(index, index + text.length),
linkBuffer.slice(index, index + text.length))

def styles: IArray[Style] = styleBuffer.clone().immutable(using Unsafe)

Expand Down Expand Up @@ -117,18 +117,17 @@ object Yossarian:
val Background = Bits(16, 0xffffff000000ffffL)

given Debug[Style] = style =>
Map(
t"Bo" -> Bit.Bold(style),
t"F" -> Bit.Faint(style),
t"I" -> Bit.Italic(style),
t"S" -> Bit.Strike(style),
t"Bl" -> Bit.Blink(style),
t"U" -> Bit.Underline(style),
t"C" -> Bit.Conceal(style),
t"R" -> Bit.Reverse(style),
)
.map { (key, value) => if value then key else t"!$key" }
.join(t"[", t" ", t" ${Foreground(style).debug} ${Background(style).debug}]")
Map
(t"Bo" -> Bit.Bold(style),
t"F" -> Bit.Faint(style),
t"I" -> Bit.Italic(style),
t"S" -> Bit.Strike(style),
t"Bl" -> Bit.Blink(style),
t"U" -> Bit.Underline(style),
t"C" -> Bit.Conceal(style),
t"R" -> Bit.Reverse(style))
.map { (key, value) => if value then key else t"!$key" }
.join(t"[", t" ", t" ${Foreground(style).debug} ${Background(style).debug}]")

enum Bit:
case Bold, Faint, Italic, Strike, Blink, Underline, Conceal, Reverse
Expand Down

0 comments on commit bc41ecc

Please sign in to comment.