Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bold and underline functionality #46

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
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 @@ -6,8 +6,8 @@
"strconv"
"strings"

"fyne.io/fyne/v2"

Check failure on line 9 in color.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.22.x, macos-latest)

missing go.sum entry for module providing package fyne.io/fyne/v2 (imported by github.com/fyne-io/terminal); to add:

Check failure on line 9 in color.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.22.x, ubuntu-latest)

missing go.sum entry for module providing package fyne.io/fyne/v2 (imported by github.com/fyne-io/terminal); to add:

Check failure on line 9 in color.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.19.x, macos-latest)

missing go.sum entry for module providing package fyne.io/fyne/v2 (imported by github.com/fyne-io/terminal); to add:

Check failure on line 9 in color.go

View workflow job for this annotation

GitHub Actions / checks

missing go.sum entry for module providing package fyne.io/fyne/v2 (imported by github.com/fyne-io/terminal); to add:

Check failure on line 9 in color.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.19.x, ubuntu-latest)

missing go.sum entry for module providing package fyne.io/fyne/v2 (imported by github.com/fyne-io/terminal); to add:
"fyne.io/fyne/v2/theme"

Check failure on line 10 in color.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.22.x, macos-latest)

missing go.sum entry for module providing package fyne.io/fyne/v2/theme (imported by github.com/fyne-io/terminal); to add:

Check failure on line 10 in color.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.22.x, ubuntu-latest)

missing go.sum entry for module providing package fyne.io/fyne/v2/theme (imported by github.com/fyne-io/terminal); to add:

Check failure on line 10 in color.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.19.x, macos-latest)

missing go.sum entry for module providing package fyne.io/fyne/v2/theme (imported by github.com/fyne-io/terminal); to add:

Check failure on line 10 in color.go

View workflow job for this annotation

GitHub Actions / checks

missing go.sum entry for module providing package fyne.io/fyne/v2/theme (imported by github.com/fyne-io/terminal); to add:

Check failure on line 10 in color.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.19.x, ubuntu-latest)

missing go.sum entry for module providing package fyne.io/fyne/v2/theme (imported by github.com/fyne-io/terminal); to add:
)

var (
Expand Down Expand Up @@ -47,6 +47,7 @@
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 @@
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
54 changes: 27 additions & 27 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,41 @@ module github.com/fyne-io/terminal
go 1.17

require (
fyne.io/fyne/v2 v2.4.0
fyne.io/fyne/v2 v2.4.3
github.com/ActiveState/termtest/conpty v0.5.0
github.com/creack/pty v1.1.11
github.com/nicksnyder/go-i18n/v2 v2.1.2
github.com/stretchr/testify v1.8.4
golang.org/x/text v0.14.0
github.com/creack/pty v1.1.21
github.com/nicksnyder/go-i18n/v2 v2.4.0
github.com/stretchr/testify v1.9.0
golang.org/x/text v0.16.0
)

require (
fyne.io/systray v1.10.1-0.20230722100817-88df1e0ffa9a // indirect
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
fyne.io/systray v1.10.1-0.20240611130111-26449f257a02 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fredbi/uri v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe // indirect
github.com/fyne-io/glfw-js v0.0.0-20220120001248-ee7290d23504 // indirect
github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2 // indirect
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b // indirect
github.com/go-text/render v0.0.0-20230619120952-35bccb6164b8 // indirect
github.com/go-text/typesetting v0.0.0-20230616162802-9c17dd34aa4a // indirect
github.com/fredbi/uri v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fyne-io/gl-js v0.0.0-20230506162202-1fdaa286a934 // indirect
github.com/fyne-io/glfw-js v0.0.0-20240101223322-6e1efdc71b7a // indirect
github.com/fyne-io/image v0.0.0-20240417123036-dc0ee9e7c964 // indirect
github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a // indirect
github.com/go-text/render v0.1.0 // indirect
github.com/go-text/typesetting v0.1.1 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/jeandeaual/go-locale v0.0.0-20240223122105-ce5225dcaa49 // indirect
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rymdport/portal v0.2.3 // indirect
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c // indirect
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect
github.com/tevino/abool v1.2.0 // indirect
github.com/yuin/goldmark v1.5.5 // indirect
golang.org/x/image v0.11.0 // indirect
golang.org/x/mobile v0.0.0-20230531173138-3c911d8e3eda // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.18.0 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
github.com/yuin/goldmark v1.7.1 // indirect
golang.org/x/image v0.17.0 // indirect
golang.org/x/mobile v0.0.0-20240604190613-2782386b8afd // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.21.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
honnef.co/go/js/dom v0.0.0-20210725211120-f030747120f2 // indirect
)
)
Loading
Loading