Skip to content

Commit ac0d0f7

Browse files
committed
feat(readme): Readme updates
Signed-off-by: dark0dave <dark0dave@mykolab.com>
1 parent 3eb00c5 commit ac0d0f7

10 files changed

Lines changed: 64 additions & 86 deletions

File tree

cmd/file-view.go

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

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 {
37+
func NewFileView(path string) fileview {
5038
content := ""
5139
if filepath.Ext(path) == ".are" {
5240
f, err := os.Open(path)
@@ -68,28 +56,42 @@ func NewFileViewFromFile(path string, callback func() (tea.Model, tea.Cmd)) file
6856
content = ""
6957
}
7058
}
71-
return NewFileView(content, filepath.Base(path), callback)
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
7267
}
7368

7469
func (f fileview) Init() tea.Cmd {
7570
return nil
7671
}
7772

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

8179
switch msg := msg.(type) {
8280
case tea.KeyMsg:
8381
if k := msg.String(); k == "ctrl+c" || k == "q" || k == "esc" {
84-
return f.callback()
82+
return f, tea.Quit
8583
}
8684

8785
case tea.WindowSizeMsg:
8886
setViewport(f, msg)
8987
}
9088

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

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

cmd/list-varriables.go

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

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

2324
func generateRows(path string, file fs.FileInfo) *[]table.Row {
2425
rows := []table.Row{}
25-
fileContent, err := util.ReadFileToString(path)
26+
fileContent, err := util.ReadFileToString(filepath.Join(path, file.Name()))
2627
if err != nil {
2728
return &rows
2829
}
2930
variables, err := translation.FromFileContents(fileContent)
3031
if err == nil {
31-
lang := filepath.Base(filepath.Dir(path))
32+
lang_path := strings.Split(path, "/")
33+
lang := ""
34+
if len(lang_path) > 2 {
35+
lang = lang_path[len(lang_path)-2]
36+
}
3237
for _, v := range *variables {
3338
rows = append(rows, table.Row{file.Name(), lang, v.Identifier, v.Value})
3439
}
@@ -38,18 +43,18 @@ func generateRows(path string, file fs.FileInfo) *[]table.Row {
3843

3944
func NewList(path string) listVariables {
4045
columns := []table.Column{
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))},
46+
{Title: "FileName", Width: 12},
47+
{Title: "Lang", Width: 8},
48+
{Title: "Id", Width: 4},
49+
{Title: "Value", Width: 40},
4550
}
4651
rows := []table.Row{}
4752
filepath.WalkDir(path, func(path string, file fs.DirEntry, err error) error {
4853
if err != nil {
4954
return err
5055
}
5156
ext := filepath.Ext(file.Name())
52-
if !file.IsDir() && strings.ToLower(ext) == ".tra" {
57+
if !file.IsDir() && ext == ".tra" {
5358
info, _ := file.Info()
5459
file_rows := *generateRows(path, info)
5560
rows = append(rows, file_rows...)
@@ -62,7 +67,7 @@ func NewList(path string) listVariables {
6267
table.WithColumns(columns),
6368
table.WithRows(rows),
6469
table.WithFocused(true),
65-
table.WithHeight(height-7),
70+
table.WithHeight(7),
6671
)
6772

6873
s := table.DefaultStyles()
@@ -86,24 +91,6 @@ func (l listVariables) Init() tea.Cmd { return nil }
8691
func (l listVariables) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
8792
var cmd tea.Cmd
8893
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-
}
10794
case tea.KeyMsg:
10895
switch msg.String() {
10996
case "esc":
@@ -112,26 +99,19 @@ func (l listVariables) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
11299
} else {
113100
l.table.Focus()
114101
}
115-
case "q", "ctrl+c", "ctrl+d":
102+
case "q", "ctrl+c":
116103
return l, tea.Quit
117104
case "enter":
118-
content := ""
105+
l.heading = []string{""}
119106
counter := 0
120-
for _, s := range strings.Split(l.table.SelectedRow()[3], " ") {
107+
for _, s := range strings.Split(l.table.SelectedRow()[2], " ") {
121108
counter += len(s)
122109
if counter >= 42 {
123-
content += "\n"
110+
l.heading = append(l.heading, "\n")
124111
counter = 0
125-
} else if strings.Trim(content, " ") != "" {
126-
content += " "
127112
}
128-
content += s
113+
l.heading = append(l.heading, s)
129114
}
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()
135115
}
136116
}
137117
l.table, cmd = l.table.Update(msg)
@@ -140,5 +120,12 @@ func (l listVariables) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
140120

141121
func (l listVariables) View() string {
142122
body := []string{l.table.View(), "\n\n", l.table.HelpView(), " enter"}
143-
return baseStyle.Render(body...)
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+
}
144131
}

cmd/tree.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ 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 := NewFileViewFromFile(node.Desc, func() (tea.Model, tea.Cmd) {
90-
return n, nil
91-
})
89+
f := NewFileView(node.Desc)
9290
return f, f.Init()
9391
}
9492
}

docs/discover.gif

4.5 MB
Loading

docs/example.gif

-8.27 MB
Binary file not shown.

docs/traverse.gif

5.54 MB
Loading

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ 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
1211
)
1312

1413
require (
@@ -31,4 +30,5 @@ require (
3130
github.com/ulikunitz/xz v0.5.12 // indirect
3231
golang.org/x/sync v0.8.0 // indirect
3332
golang.org/x/sys v0.27.0 // indirect
33+
golang.org/x/text v0.3.8 // indirect
3434
)

pkg/translation/varriables.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ 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"
116
)
127

138
var (
@@ -41,14 +36,6 @@ func (v *Variable) end() int {
4136
return v.valueEnd
4237
}
4338

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-
5239
func FromString(s string, start int) (*Variable, error) {
5340
v := &Variable{}
5441
for i := start; i < len(s); i++ {
@@ -72,7 +59,7 @@ func FromString(s string, start int) (*Variable, error) {
7259
// "~" is 126
7360
if v.isRecording() && s[i] == 126 {
7461
v.valueEnd = i
75-
v.Value = ToAscii(s[v.valueStart:v.valueEnd])
62+
v.Value = s[v.valueStart:v.valueEnd]
7663
v.toggleRecording()
7764
break
7865
}

pkg/translation/varriables_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ 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-
},
4032
}
4133
for _, tc := range testCases {
4234
v, err := FromString(tc.testString, 0)

readme.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,23 @@
66
[![](https://img.shields.io/github/actions/workflow/status/dark0dave/infinity_dialog/main.yaml?style=for-the-badge)](https://github.com/dark0dave/infinity_dialog/actions/workflows/main.yaml)
77
[![](https://img.shields.io/github/license/dark0dave/infinity_dialog?style=for-the-badge)](./LICENSE)
88

9-
This tool interacts with .tra files used in infinity engine mods. Currently we walk a directory of a mod and allow you to browse the strings.
9+
This tool has 2 features, traverse and discover. Traverse walks over a bg mod and shows you the tree of paths through the files. Discover shows all the strings for all languages and where they are set.
1010

11-
## Demo
11+
### Traverse
1212

13-
![](./docs/example.gif)
13+
This feature lets you see the paths through your mod by parsing the area + baf files.
14+
15+
#### Demo
16+
17+
![](./docs/traverse.gif)
18+
19+
### Discover
20+
21+
This feature interacts with .tra files used in infinity engine mods. Currently we walk a directory of a mod and allow you to browse the strings.
22+
23+
#### Demo
24+
25+
![](./docs/discover.gif)
1426

1527
## Run
1628

0 commit comments

Comments
 (0)