Skip to content

Commit eeefd7b

Browse files
authored
Create model.go
1 parent ec9994b commit eeefd7b

1 file changed

Lines changed: 140 additions & 0 deletions

File tree

source-code/src/model.go

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
package src
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"time"
7+
8+
"github.com/charmbracelet/bubbles/list"
9+
"github.com/charmbracelet/bubbles/progress"
10+
"github.com/charmbracelet/bubbles/textarea"
11+
"github.com/charmbracelet/bubbles/textinput"
12+
"github.com/charmbracelet/bubbles/viewport"
13+
tea "github.com/charmbracelet/bubbletea"
14+
"github.com/charmbracelet/lipgloss"
15+
)
16+
17+
type item struct {
18+
title, desc string
19+
status string // For Git status
20+
selected bool
21+
isDir bool
22+
size int64
23+
modTime time.Time
24+
}
25+
26+
func (i item) Title() string {
27+
title := i.title
28+
if i.selected {
29+
title = "* " + title
30+
}
31+
if i.status != "" {
32+
switch i.status[0] {
33+
case 'M':
34+
title = gitModifiedStyle.Render(title)
35+
case 'A':
36+
title = gitAddedStyle.Render(title)
37+
case 'D':
38+
title = gitDeletedStyle.Render(title)
39+
}
40+
}
41+
return title
42+
}
43+
44+
func (i item) Description() string {
45+
return fmt.Sprintf("%s | Size: %d | Mod: %s", i.desc, i.size, i.modTime.Format("2006-01-02 15:04"))
46+
}
47+
48+
func (i item) FilterValue() string { return i.title }
49+
50+
type CommandResult struct {
51+
Output string
52+
Err error
53+
}
54+
55+
type ProgressMsg struct {
56+
Percent float64
57+
}
58+
59+
type tickMsg time.Time
60+
61+
type panel struct {
62+
currentDir string
63+
gitBranch string
64+
fileList list.Model
65+
selectedFiles map[string]bool
66+
preview viewport.Model
67+
vfs vfsHandler
68+
}
69+
70+
type Model struct {
71+
panels [2]panel
72+
activePanel int
73+
commandInput textinput.Model
74+
statusMsg string
75+
keys keyMap
76+
mode mode
77+
editor textarea.Model
78+
editorFile string
79+
progress progress.Model
80+
quitting bool
81+
ProgressChan chan ProgressMsg
82+
ResultChan chan CommandResult
83+
fuzzyInput textinput.Model
84+
fuzzyResults []string
85+
bulkRenameFrom string
86+
bulkRenameTo string
87+
subShell bool
88+
}
89+
90+
func InitialModel() Model {
91+
wd, _ := os.Getwd()
92+
ti := textinput.New()
93+
ti.Placeholder = "Enter command (e.g., cd .., mv file1 file2, sftp://user:pass@host)"
94+
ti.Focus()
95+
ti.Width = 80
96+
del := list.NewDefaultDelegate()
97+
del.Styles.SelectedTitle = del.Styles.SelectedTitle.Foreground(lipgloss.Color("#FFFFFF")).Bold(true)
98+
del.Styles.NormalTitle = del.Styles.NormalTitle.Foreground(lipgloss.Color("#CCCCCC"))
99+
l1 := list.New([]list.Item{}, del, 0, 0)
100+
l1.Title = "Left Panel"
101+
l1.Styles.Title = subtitleStyle
102+
l1.SetShowFilter(true)
103+
l2 := list.New([]list.Item{}, del, 0, 0)
104+
l2.Title = "Right Panel"
105+
l2.Styles.Title = subtitleStyle
106+
l2.SetShowFilter(true)
107+
ta := textarea.New()
108+
ta.Placeholder = "Edit your file here..."
109+
ta.Focus()
110+
pv1 := viewport.New(0, 0)
111+
pv1.SetContent("Preview")
112+
pv2 := viewport.New(0, 0)
113+
pv2.SetContent("Preview")
114+
prog := progress.New(progress.WithDefaultGradient())
115+
fi := textinput.New()
116+
fi.Placeholder = "Fuzzy search..."
117+
m := Model{
118+
panels: [2]panel{
119+
{currentDir: wd, fileList: l1, selectedFiles: make(map[string]bool), preview: pv1, vfs: localVFS{}},
120+
{currentDir: wd, fileList: l2, selectedFiles: make(map[string]bool), preview: pv2, vfs: localVFS{}},
121+
},
122+
activePanel: 0,
123+
commandInput: ti,
124+
keys: newKeyMap(),
125+
mode: explorerMode,
126+
editor: ta,
127+
progress: prog,
128+
ProgressChan: make(chan ProgressMsg),
129+
ResultChan: make(chan CommandResult),
130+
fuzzyInput: fi,
131+
}
132+
for i := range m.panels {
133+
m.refreshPanel(i)
134+
}
135+
return m
136+
}
137+
138+
func (m Model) Init() tea.Cmd {
139+
return textinput.Blink
140+
}

0 commit comments

Comments
 (0)