Skip to content

Commit f1831b1

Browse files
committed
fix(cliff): Fixed double changelog
Signed-off-by: dark0dave <dark0dave@mykolab.com>
1 parent f7b03f4 commit f1831b1

7 files changed

Lines changed: 83 additions & 56 deletions

File tree

cliff.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ body = """\
2323
{% else %} by [{{ commit.author.name }}](https://github.com/{{ commit.author.name }}){%- endif %}\
2424
{%- endfor -%}
2525
{% endfor %}
26-
{% if version %}
27-
{% if previous.version %}\
28-
Full Changelog: [{{ previous.version }}...{{ version }}]({{ self::remote_url() }}/compare/{{ previous.version }}...{{ version }})\
29-
{% endif %}\
30-
{% else -%}\
31-
{% raw %}\n{% endraw %}\
32-
{% endif %}\
3326
{% if github.contributors | filter(attribute="is_first_time", value=true) | length != 0 %}
3427
### New Contributors
3528
{% for contributor in github.contributors | filter(attribute="is_first_time", value=true) %}

cmd/file-view.go

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,21 @@ type fileview struct {
3232
title string
3333
content string
3434
viewport viewport.Model
35+
callback func() (tea.Model, tea.Cmd)
3536
}
3637

37-
func NewFileView(path string) fileview {
38+
func NewFileView(content string, title string, callback func() (tea.Model, tea.Cmd)) fileview {
39+
f := fileview{title: title, content: content, callback: callback}
40+
headerHeight := lipgloss.Height(f.headerView())
41+
footerHeight := lipgloss.Height(f.footerView())
42+
verticalMarginHeight := headerHeight + footerHeight
43+
f.viewport = viewport.New(width, height-verticalMarginHeight)
44+
f.viewport.YPosition = headerHeight
45+
f.viewport.SetContent(f.content)
46+
return f
47+
}
48+
49+
func NewFileViewFromFile(path string, callback func() (tea.Model, tea.Cmd)) fileview {
3850
content := ""
3951
if filepath.Ext(path) == ".are" {
4052
f, err := os.Open(path)
@@ -56,42 +68,28 @@ func NewFileView(path string) fileview {
5668
content = ""
5769
}
5870
}
59-
f := fileview{title: filepath.Base(path), content: content}
60-
headerHeight := lipgloss.Height(f.headerView())
61-
footerHeight := lipgloss.Height(f.footerView())
62-
verticalMarginHeight := headerHeight + footerHeight
63-
f.viewport = viewport.New(width, height-verticalMarginHeight)
64-
f.viewport.YPosition = headerHeight
65-
f.viewport.SetContent(f.content)
66-
return f
71+
return NewFileView(content, filepath.Base(path), callback)
6772
}
6873

6974
func (f fileview) Init() tea.Cmd {
7075
return nil
7176
}
7277

7378
func (f fileview) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
74-
var (
75-
cmd tea.Cmd
76-
cmds []tea.Cmd
77-
)
79+
var cmd tea.Cmd
7880

7981
switch msg := msg.(type) {
8082
case tea.KeyMsg:
8183
if k := msg.String(); k == "ctrl+c" || k == "q" || k == "esc" {
82-
return f, tea.Quit
84+
return f.callback()
8385
}
8486

8587
case tea.WindowSizeMsg:
8688
setViewport(f, msg)
8789
}
8890

89-
// Handle keyboard and mouse events in the viewport
9091
f.viewport, cmd = f.viewport.Update(msg)
91-
// Send an extra WindowSize to update
92-
cmds = append(cmds, cmd)
93-
94-
return f, tea.Batch(cmds...)
92+
return f, cmd
9593
}
9694

9795
func setViewport(f fileview, msg tea.WindowSizeMsg) {

cmd/list-varriables.go

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,18 @@ var baseStyle = lipgloss.NewStyle().
1717
BorderForeground(lipgloss.Color("240"))
1818

1919
type listVariables struct {
20-
heading []string
21-
table table.Model
20+
table table.Model
2221
}
2322

2423
func generateRows(path string, file fs.FileInfo) *[]table.Row {
2524
rows := []table.Row{}
26-
fileContent, err := util.ReadFileToString(filepath.Join(path, file.Name()))
25+
fileContent, err := util.ReadFileToString(path)
2726
if err != nil {
2827
return &rows
2928
}
3029
variables, err := translation.FromFileContents(fileContent)
3130
if err == nil {
32-
lang_path := strings.Split(path, "/")
33-
lang := ""
34-
if len(lang_path) > 2 {
35-
lang = lang_path[len(lang_path)-2]
36-
}
31+
lang := filepath.Base(filepath.Dir(path))
3732
for _, v := range *variables {
3833
rows = append(rows, table.Row{file.Name(), lang, v.Identifier, v.Value})
3934
}
@@ -43,18 +38,18 @@ func generateRows(path string, file fs.FileInfo) *[]table.Row {
4338

4439
func NewList(path string) listVariables {
4540
columns := []table.Column{
46-
{Title: "FileName", Width: 12},
47-
{Title: "Lang", Width: 8},
48-
{Title: "Id", Width: 4},
49-
{Title: "Value", Width: 40},
41+
{Title: "FileName", Width: int(0.2 * float64(width))},
42+
{Title: "Lang", Width: int(0.1 * float64(width))},
43+
{Title: "Id", Width: int(0.05 * float64(width))},
44+
{Title: "Value", Width: int(0.55 * float64(width))},
5045
}
5146
rows := []table.Row{}
5247
filepath.WalkDir(path, func(path string, file fs.DirEntry, err error) error {
5348
if err != nil {
5449
return err
5550
}
5651
ext := filepath.Ext(file.Name())
57-
if !file.IsDir() && ext == ".tra" {
52+
if !file.IsDir() && strings.ToLower(ext) == ".tra" {
5853
info, _ := file.Info()
5954
file_rows := *generateRows(path, info)
6055
rows = append(rows, file_rows...)
@@ -67,7 +62,7 @@ func NewList(path string) listVariables {
6762
table.WithColumns(columns),
6863
table.WithRows(rows),
6964
table.WithFocused(true),
70-
table.WithHeight(7),
65+
table.WithHeight(height-7),
7166
)
7267

7368
s := table.DefaultStyles()
@@ -91,6 +86,24 @@ func (l listVariables) Init() tea.Cmd { return nil }
9186
func (l listVariables) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
9287
var cmd tea.Cmd
9388
switch msg := msg.(type) {
89+
case tea.WindowSizeMsg:
90+
h, w := docStyle.GetFrameSize()
91+
h1, w1 := baseStyle.GetFrameSize()
92+
h += h1
93+
w += w1
94+
if msg.Height > h {
95+
l.table.SetHeight(msg.Height - h)
96+
}
97+
if msg.Width > w {
98+
ratio := float64(msg.Width - w)
99+
l.table.SetColumns([]table.Column{
100+
{Title: "FileName", Width: int(0.2 * ratio)},
101+
{Title: "Lang", Width: int(0.1 * ratio)},
102+
{Title: "Id", Width: int(0.05 * ratio)},
103+
{Title: "Value", Width: int(0.55 * ratio)},
104+
})
105+
l.table.SetWidth(int(ratio))
106+
}
94107
case tea.KeyMsg:
95108
switch msg.String() {
96109
case "esc":
@@ -99,19 +112,26 @@ func (l listVariables) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
99112
} else {
100113
l.table.Focus()
101114
}
102-
case "q", "ctrl+c":
115+
case "q", "ctrl+c", "ctrl+d":
103116
return l, tea.Quit
104117
case "enter":
105-
l.heading = []string{""}
118+
content := ""
106119
counter := 0
107-
for _, s := range strings.Split(l.table.SelectedRow()[2], " ") {
120+
for _, s := range strings.Split(l.table.SelectedRow()[3], " ") {
108121
counter += len(s)
109122
if counter >= 42 {
110-
l.heading = append(l.heading, "\n")
123+
content += "\n"
111124
counter = 0
125+
} else if strings.Trim(content, " ") != "" {
126+
content += " "
112127
}
113-
l.heading = append(l.heading, s)
128+
content += s
114129
}
130+
title := strings.Join(l.table.SelectedRow()[:3], " ")
131+
f := NewFileView(content, title, func() (tea.Model, tea.Cmd) {
132+
return l, cmd
133+
})
134+
return f, f.Init()
115135
}
116136
}
117137
l.table, cmd = l.table.Update(msg)
@@ -120,12 +140,5 @@ func (l listVariables) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
120140

121141
func (l listVariables) View() string {
122142
body := []string{l.table.View(), "\n\n", l.table.HelpView(), " enter"}
123-
if len(l.heading) == 0 {
124-
return baseStyle.Render(body...)
125-
} else {
126-
payload := l.heading
127-
payload = append(payload, "\n")
128-
payload = append(payload, body...)
129-
return baseStyle.Render(payload...)
130-
}
143+
return baseStyle.Render(body...)
131144
}

cmd/tree.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ func (n nested) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
8686
case "e", "enter":
8787
nodes := n.tree.Nodes()
8888
node, _ := getSelected(&n, &nodes, 0)
89-
f := NewFileView(node.Desc)
89+
f := NewFileViewFromFile(node.Desc, func() (tea.Model, tea.Cmd) {
90+
return n, nil
91+
})
9092
return f, f.Init()
9193
}
9294
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/charmbracelet/lipgloss v0.13.0
99
github.com/dark0dave/infinity_file_formats v0.0.0-20241126215235-54369c958d54
1010
github.com/savannahostrowski/tree-bubble v0.0.0-20230724043728-d7bb06a8a67e
11+
golang.org/x/text v0.3.8
1112
)
1213

1314
require (
@@ -30,5 +31,4 @@ require (
3031
github.com/ulikunitz/xz v0.5.12 // indirect
3132
golang.org/x/sync v0.8.0 // indirect
3233
golang.org/x/sys v0.27.0 // indirect
33-
golang.org/x/text v0.3.8 // indirect
3434
)

pkg/translation/varriables.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ package translation
33
import (
44
"errors"
55
"fmt"
6+
"unicode"
7+
8+
"golang.org/x/text/runes"
9+
"golang.org/x/text/transform"
10+
"golang.org/x/text/unicode/norm"
611
)
712

813
var (
@@ -36,6 +41,14 @@ func (v *Variable) end() int {
3641
return v.valueEnd
3742
}
3843

44+
func ToAscii(str string) string {
45+
result, _, err := transform.String(transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn))), str)
46+
if err != nil {
47+
return ""
48+
}
49+
return result
50+
}
51+
3952
func FromString(s string, start int) (*Variable, error) {
4053
v := &Variable{}
4154
for i := start; i < len(s); i++ {
@@ -59,7 +72,7 @@ func FromString(s string, start int) (*Variable, error) {
5972
// "~" is 126
6073
if v.isRecording() && s[i] == 126 {
6174
v.valueEnd = i
62-
v.Value = s[v.valueStart:v.valueEnd]
75+
v.Value = ToAscii(s[v.valueStart:v.valueEnd])
6376
v.toggleRecording()
6477
break
6578
}

pkg/translation/varriables_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ func TestString(t *testing.T) {
2929
testString: "@123 test string~",
3030
error: ErrValue,
3131
},
32+
{
33+
expected: &Variable{
34+
Identifier: "0",
35+
Value: "Aboleth le�� ve sv� n�dr�i, mimo dosah tv�ch zbran�. Mus� naj�t jin� zp�sob, jak zni�it mechanismus, kter� ho dr�� na�ivu.",
36+
},
37+
testString: "@0 = ~Aboleth le�� ve sv� n�dr�i, mimo dosah tv�ch zbran�. Mus� naj�t jin� zp�sob, jak zni�it mechanismus, kter� ho dr�� na�ivu.~",
38+
error: nil,
39+
},
3240
}
3341
for _, tc := range testCases {
3442
v, err := FromString(tc.testString, 0)

0 commit comments

Comments
 (0)