Skip to content

Commit

Permalink
prevent combining unicode characters to display on windows (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviergodart committed Nov 6, 2024
1 parent 84e1024 commit 9c12334
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 31 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/charmbracelet/bubbletea v1.1.0
github.com/charmbracelet/lipgloss v0.13.0
gitlab.com/gomidi/midi/v2 v2.2.10
golang.org/x/text v0.17.0
)

require (
Expand All @@ -25,4 +24,5 @@ require (
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
)
4 changes: 2 additions & 2 deletions ui/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"signls/core/common"
"signls/filesystem"
"signls/ui/param"
"signls/ui/util"

"github.com/charmbracelet/lipgloss"
"golang.org/x/text/unicode/norm"
)

const (
Expand Down Expand Up @@ -218,7 +218,7 @@ func (m mainModel) selectedNodeName() string {
func bankGridLabel(nb int, g filesystem.Grid) string {
label := fmt.Sprintf("%2d", nb+1)
if !g.IsEmpty() {
label = norm.NFC.String(fmt.Sprintf("%2d\u0320", nb+1))
label = util.Normalize(fmt.Sprintf("%2d\u0320", nb+1))
}
return label
}
4 changes: 2 additions & 2 deletions ui/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"signls/core/music"
"signls/core/node"
"signls/ui/param"
"signls/ui/util"

"github.com/charmbracelet/lipgloss"
"golang.org/x/text/unicode/norm"
)

var (
Expand Down Expand Up @@ -81,7 +81,7 @@ func (m mainModel) renderNode(n common.Node, x, y int) string {
}
return activeEmitterStyle.Render(" ")
case music.Audible:
symbol := norm.NFC.String(n.Symbol())
symbol := util.Normalize(n.Symbol())

if isCursor && !m.edit {
return cursorStyle.Render(symbol)
Expand Down
5 changes: 2 additions & 3 deletions ui/param/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (

"signls/core/common"
"signls/core/music"

"golang.org/x/text/unicode/norm"
"signls/ui/util"
)

type Channel struct {
Expand All @@ -19,7 +18,7 @@ func (c Channel) Name() string {

func (c Channel) Display() string {
if c.nodes[0].(music.Audible).Note().Channel.RandomAmount() != 0 {
return norm.NFC.String(
return util.Normalize(
fmt.Sprintf(
"%d%+d\u033c",
c.nodes[0].(music.Audible).Note().Channel.Value()+1,
Expand Down
4 changes: 2 additions & 2 deletions ui/param/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"signls/core/common"
"signls/core/music"

"golang.org/x/text/unicode/norm"
"signls/ui/util"
)

type KeyMode uint8
Expand All @@ -34,7 +34,7 @@ func (k *Key) Display() string {
}

if k.nodes[0].(music.Audible).Note().Key.RandomAmount() != 0 {
return norm.NFC.String(
return util.Normalize(
fmt.Sprintf(
"%s%+d\u033c",
k.nodes[0].(music.Audible).Note().Key.Display(),
Expand Down
5 changes: 2 additions & 3 deletions ui/param/length.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (

"signls/core/common"
"signls/core/music"

"golang.org/x/text/unicode/norm"
"signls/ui/util"
)

const (
Expand Down Expand Up @@ -44,7 +43,7 @@ func (l Length) Display() string {
display = fmt.Sprintf("%.1f", float64(length)/float64(pulsesPerStep))
}
if l.nodes[0].(music.Audible).Note().Length.RandomAmount() != 0 {
return norm.NFC.String(
return util.Normalize(
fmt.Sprintf(
"%s%+.1f\u033c",
display,
Expand Down
4 changes: 2 additions & 2 deletions ui/param/offset.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"signls/core/common"
"signls/core/node"

"golang.org/x/text/unicode/norm"
"signls/ui/util"
)

type Offset struct {
Expand All @@ -19,7 +19,7 @@ func (o Offset) Name() string {

func (o Offset) Display() string {
if o.nodes[0].(*node.EuclidEmitter).Offset.RandomAmount() != 0 {
return norm.NFC.String(
return util.Normalize(
fmt.Sprintf(
"%d%+d\u033c",
o.nodes[0].(*node.EuclidEmitter).Offset.Value(),
Expand Down
4 changes: 2 additions & 2 deletions ui/param/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"signls/core/common"
"signls/core/node"

"golang.org/x/text/unicode/norm"
"signls/ui/util"
)

type Steps struct {
Expand All @@ -19,7 +19,7 @@ func (s Steps) Name() string {

func (s Steps) Display() string {
if s.nodes[0].(*node.EuclidEmitter).Steps.RandomAmount() != 0 {
return norm.NFC.String(
return util.Normalize(
fmt.Sprintf(
"%d%+d\u033c",
s.nodes[0].(*node.EuclidEmitter).Steps.Value(),
Expand Down
4 changes: 2 additions & 2 deletions ui/param/threshold.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"signls/core/common"
"signls/core/node"

"golang.org/x/text/unicode/norm"
"signls/ui/util"
)

type Threshold struct {
Expand All @@ -20,7 +20,7 @@ func (t Threshold) Name() string {

func (t Threshold) Display() string {
if t.control().RandomAmount() != 0 {
return norm.NFC.String(
return util.Normalize(
fmt.Sprintf(
"%d%+d\u033c",
t.control().Value(),
Expand Down
5 changes: 2 additions & 3 deletions ui/param/triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (

"signls/core/common"
"signls/core/node"

"golang.org/x/text/unicode/norm"
"signls/ui/util"
)

const (
Expand All @@ -23,7 +22,7 @@ func (t Triggers) Name() string {

func (t Triggers) Display() string {
if t.nodes[0].(*node.EuclidEmitter).Triggers.RandomAmount() != 0 {
return norm.NFC.String(
return util.Normalize(
fmt.Sprintf(
"%d%+d\u033c",
t.nodes[0].(*node.EuclidEmitter).Triggers.Value(),
Expand Down
5 changes: 2 additions & 3 deletions ui/param/velocity.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (

"signls/core/common"
"signls/core/music"

"golang.org/x/text/unicode/norm"
"signls/ui/util"
)

type Velocity struct {
Expand All @@ -19,7 +18,7 @@ func (v Velocity) Name() string {

func (v Velocity) Display() string {
if v.nodes[0].(music.Audible).Note().Velocity.RandomAmount() != 0 {
return norm.NFC.String(
return util.Normalize(
fmt.Sprintf(
"%d%+d\u033c",
v.nodes[0].(music.Audible).Note().Velocity.Value(),
Expand Down
3 changes: 2 additions & 1 deletion ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"signls/core/node"
"signls/filesystem"
"signls/ui/param"
"signls/ui/util"

"github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/key"
Expand Down Expand Up @@ -467,5 +468,5 @@ func moveCursor(dir string, speed, x, y, minX, maxX, minY, maxY int) (int, int)
default:
newX, newY = 0, 0
}
return clamp(newX, minX, maxX), clamp(newY, minY, maxY)
return util.Clamp(newX, minX, maxX), util.Clamp(newY, minY, maxY)
}
5 changes: 0 additions & 5 deletions ui/util.go

This file was deleted.

22 changes: 22 additions & 0 deletions ui/util/norm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package util

import (
"runtime"
"strings"
"unicode"
)

// Normalize process strings with unicode characters
// to handle weird behaviors on specific platforms.
// Mainly for windows right now.
func Normalize(text string) string {
if runtime.GOOS != "windows" {
return text
}
return strings.Map(func(r rune) rune {
if unicode.IsMark(r) {
return -1
}
return r
}, text)
}
5 changes: 5 additions & 0 deletions ui/util/value.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package util

func Clamp(value, minimum, maximum int) int {
return max(min(value, maximum), minimum)
}

0 comments on commit 9c12334

Please sign in to comment.