Skip to content

Commit

Permalink
Removed external lib to fill commandline
Browse files Browse the repository at this point in the history
Added implemantation to handle pts
  • Loading branch information
grrlopes committed Aug 5, 2023
1 parent d100c6d commit 9de610b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions helper/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ var (
ErrNotExists = errors.New("row not exists")
ErrUpdateFailed = errors.New("update failed")
ErrDeleteFailed = errors.New("delete failed")
ErrEnvFailed = errors.New("You must set up env as\n export storydb=$(tty)")
)
31 changes: 23 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package main

import (
"fmt"
"log"
"os"
"os/exec"
"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"
Expand Down Expand Up @@ -55,14 +58,26 @@ func main() {

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)
}

cmd := exec.Command(
"xdotool",
"type",
m.home.GetSelected(),
)
_ = cmd.Run()
fmt.Printf("%+v\n\n", " --")
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", "---")
}
1 change: 1 addition & 0 deletions ui/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func (m ModelHome) Update(msg tea.Msg) (*ModelHome, tea.Cmd) {
return &m, tea.Quit
case "/":
m.home.Finder.Focus()
m.home.Pagination.Page = 0
}
}
case tea.WindowSizeMsg:
Expand Down

0 comments on commit 9de610b

Please sign in to comment.