go fmt sources & add command-line file loading
This commit is contained in:
parent
d0bb43cc8f
commit
443070f077
21
main.go
21
main.go
@ -2,9 +2,9 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"io/fs"
|
||||
|
||||
"github.com/fivemoreminix/diesel/ui"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
@ -47,6 +47,25 @@ func main() {
|
||||
tabContainer.SetPos(0, 1)
|
||||
tabContainer.SetSize(sizex, sizey-1)
|
||||
|
||||
// Load files from command-line arguments
|
||||
if len(os.Args) > 1 {
|
||||
for _, path := range os.Args[1:] {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
panic("File could not be opened at path " + path)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
bytes, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
panic("Could not read all of " + path)
|
||||
}
|
||||
|
||||
textEdit := ui.NewTextEdit(&s, path, string(bytes), &theme)
|
||||
tabContainer.AddTab(path, textEdit)
|
||||
}
|
||||
}
|
||||
|
||||
var fileSelector *ui.FileSelectorDialog // if nil, we don't draw it
|
||||
|
||||
bar := ui.NewMenuBar(nil, &theme)
|
||||
|
@ -160,7 +160,7 @@ func (c *TabContainer) Draw(s tcell.Screen) {
|
||||
for _, tab := range c.children {
|
||||
combinedTabLength += len(tab.Name) + 2 // 2 for padding
|
||||
}
|
||||
combinedTabLength += len(c.children)-1 // add for spacing between tabs
|
||||
combinedTabLength += len(c.children) - 1 // add for spacing between tabs
|
||||
|
||||
// Draw tabs
|
||||
col := c.x + c.width/2 - combinedTabLength/2 // Starting column
|
||||
@ -239,10 +239,10 @@ func (c *TabContainer) HandleEvent(event tcell.Event) bool {
|
||||
if c.Selected >= len(c.children) {
|
||||
c.Selected = 0
|
||||
}
|
||||
} else if ev.Modifiers() == tcell.ModCtrl & tcell.ModShift { // Ctrl + Shift + Tab was pressed
|
||||
} else if ev.Modifiers() == tcell.ModCtrl&tcell.ModShift { // Ctrl + Shift + Tab was pressed
|
||||
c.Selected--
|
||||
if c.Selected < 0 {
|
||||
c.Selected = len(c.children)-1
|
||||
c.Selected = len(c.children) - 1
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -281,7 +281,7 @@ func (w *WindowContainer) Draw(s tcell.Screen) {
|
||||
headerStyle := w.Theme.GetOrDefault("WindowHeader")
|
||||
|
||||
DrawRect(s, w.x, w.y, w.width, 1, ' ', headerStyle) // Draw header
|
||||
DrawStr(s, w.x+w.width/2 - len(w.Title)/2, w.y, w.Title, headerStyle) // Draw title
|
||||
DrawStr(s, w.x+w.width/2-len(w.Title)/2, w.y, w.Title, headerStyle) // Draw title
|
||||
DrawRect(s, w.x, w.y+1, w.width, w.height-1, ' ', w.Theme.GetOrDefault("Window")) // Draw body background
|
||||
|
||||
if w.Child != nil {
|
||||
|
@ -40,7 +40,7 @@ func (f *InputField) SetCursorPos(offset int) {
|
||||
|
||||
// Scrolling
|
||||
if offset >= f.scrollPos+f.width-2 { // If cursor position is out of view to the right...
|
||||
f.scrollPos = offset - f.width+2 // Scroll just enough to view that column
|
||||
f.scrollPos = offset - f.width + 2 // Scroll just enough to view that column
|
||||
} else if offset < f.scrollPos { // If cursor position is out of view to the left...
|
||||
f.scrollPos = offset
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user