/
main.go
82 lines (66 loc) · 1.51 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"fmt"
"log"
"os"
"syscall"
"unsafe"
tea "github.com/charmbracelet/bubbletea"
"github.com/grrlopes/storydb/entity"
"github.com/grrlopes/storydb/helper"
"github.com/grrlopes/storydb/repositories"
"github.com/grrlopes/storydb/repositories/sqlite"
"github.com/grrlopes/storydb/ui"
"github.com/grrlopes/storydb/usecase/schema"
)
var (
repositoryGorm repositories.ISqliteRepository = sqlite.NewGormRepostory()
usecaseMigrateGorm schema.InputBoundary = schema.NewMigrate(repositoryGorm)
)
type model struct {
home *ui.ModelHome
}
func (m model) Init() tea.Cmd {
return nil
}
func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
m.home, cmd = m.home.Update(msg)
return m, cmd
}
func (m model) View() string {
return m.home.View()
}
func main() {
usecaseMigrateGorm.Execute()
m := model{
home: ui.NewHome(
&entity.CmdModel{},
),
}
p := tea.NewProgram(
&m,
tea.WithAltScreen(),
)
_, err := p.Run()
if err != nil {
fmt.Println("could not run program:", err)
}
env := os.Getenv("storydb")
if env == "" {
log.Fatalf("%s %s", "Error", helper.ErrEnvFailed)
}
fd, err := syscall.Open(env, syscall.O_RDWR, 0)
if err != nil {
fmt.Println("Error opening Device:", err)
os.Exit(1)
}
defer syscall.Close(fd)
cmd := m.home.GetSelected()
for i := 0; i < len(cmd); i++ {
char := cmd[i]
b := []byte{char}
syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), syscall.TIOCSTI, uintptr(unsafe.Pointer(&b[0])))
}
fmt.Printf("%+v\n\n", "---")
}