Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
26 changes: 26 additions & 0 deletions cmd/fyneterm/font/NotoSansMono/notosansmono.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package notosansmono

import (
// go embed.
_ "embed"

"fyne.io/fyne/v2"
)

//go:embed NotoSansMono-Regular.ttf
var regular []byte

// Regular is the regular font resource.
var Regular = &fyne.StaticResource{
StaticName: "NotoSansMono-Regular.ttf",
StaticContent: regular,
}

//go:embed NotoSansMono-Bold.ttf
var bold []byte

// Bold is the bold font resource.
var Bold = &fyne.StaticResource{
StaticName: "NotoSansMono-Bold.ttf",
StaticContent: bold,
}
10 changes: 10 additions & 0 deletions cmd/fyneterm/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/theme"
notosansmono "github.com/fyne-io/terminal/cmd/fyneterm/font/NotoSansMono"
)

type termTheme struct {
Expand Down Expand Up @@ -41,3 +42,12 @@ func (t *termTheme) Size(n fyne.ThemeSizeName) float32 {

return t.Theme.Size(n)
}

func (t *termTheme) Font(style fyne.TextStyle) fyne.Resource {
switch {
case style.Bold:
return notosansmono.Bold
default:
return notosansmono.Regular
}
}
7 changes: 6 additions & 1 deletion color.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (t *Terminal) handleColorEscape(message string) {
t.currentFG = nil
t.bold = false
t.blinking = false
t.underlined = false
return
}
modes := strings.Split(message, ";")
Expand Down Expand Up @@ -82,11 +83,15 @@ func (t *Terminal) handleColorMode(modeStr string) {
t.currentBG, t.currentFG = nil, nil
t.bold = false
t.blinking = false
t.underlined = false
case 1:
t.bold = true
case 4, 24: //italic
case 4:
t.underlined = true
case 5:
t.blinking = true
case 24:
t.underlined = false
case 7: // reverse
bg, fg := t.currentBG, t.currentFG
if fg == nil {
Expand Down
27 changes: 21 additions & 6 deletions color_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,23 @@ func testColor(t *testing.T, tests map[string]struct {

func TestHandleOutput_Text(t *testing.T) {
tests := map[string]struct {
inputSeq string
expectBold bool
inputSeq string
expectBold bool
expectUnderline bool
}{
"bold": {
inputSeq: esc("[1m"),
expectBold: true,
},
"underline": {
inputSeq: esc("[4m"),
expectUnderline: true,
},
"bold and underline": {
inputSeq: esc("[1m") + esc("[4m"),
expectBold: true,
expectUnderline: true,
},
}

// Iterate through the test cases
Expand All @@ -60,6 +70,11 @@ func TestHandleOutput_Text(t *testing.T) {
terminal := New()
terminal.handleOutput([]byte(test.inputSeq))

// Verify the actual results match the expected results
if terminal.underlined != test.expectUnderline {
t.Errorf("Bold flag mismatch. Got %v, expected %v", terminal.underlined, test.expectUnderline)
}

if terminal.bold != test.expectBold {
t.Errorf("Bold flag mismatch. Got %v, expected %v", terminal.bold, test.expectBold)
}
Expand Down Expand Up @@ -921,10 +936,10 @@ func TestHandleOutput_BufferCutoff(t *testing.T) {
tg.Rows = []widget.TextGridRow{
{
Cells: []widget.TextGridCell{
{Rune: '4', Style: &widget.CustomTextGridStyle{FGColor: c1, BGColor: nil}},
{Rune: '0', Style: &widget.CustomTextGridStyle{FGColor: c1, BGColor: nil}},
{Rune: '4', Style: &widget.CustomTextGridStyle{FGColor: c2, BGColor: nil}},
{Rune: '1', Style: &widget.CustomTextGridStyle{FGColor: c2, BGColor: nil}},
{Rune: '4', Style: widget2.NewTermTextGridStyle(c1, nil, 0x55, false, false, false)},
{Rune: '0', Style: widget2.NewTermTextGridStyle(c1, nil, 0x55, false, false, false)},
{Rune: '4', Style: widget2.NewTermTextGridStyle(c2, nil, 0x55, false, false, false)},
{Rune: '1', Style: widget2.NewTermTextGridStyle(c2, nil, 0x55, false, false, false)},
},
},
}
Expand Down
Loading
Loading