mirror of
https://github.com/EnumeratedDev/Typer.git
synced 2025-07-01 07:48:20 +00:00
Open file buffers through command arguments
This commit is contained in:
parent
6b5e6e8996
commit
2f7f483563
24
src/main.go
24
src/main.go
@ -2,14 +2,36 @@ package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
window, err := CreateWindow(nil)
|
||||
window, err := CreateWindow()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create window: %v", err)
|
||||
}
|
||||
|
||||
var initialBuffer *Buffer = nil
|
||||
|
||||
if len(os.Args) > 0 {
|
||||
for _, file := range os.Args[1:] {
|
||||
b, err := CreateFileBuffer(file)
|
||||
if err != nil {
|
||||
PrintMessage(window, "Could not open file: "+file)
|
||||
continue
|
||||
}
|
||||
Buffers[b.Id] = b
|
||||
if initialBuffer == nil {
|
||||
initialBuffer = b
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if initialBuffer != nil {
|
||||
delete(Buffers, window.textArea.CurrentBuffer.Id)
|
||||
window.textArea.CurrentBuffer = initialBuffer
|
||||
}
|
||||
|
||||
for window.screen != nil {
|
||||
window.Draw()
|
||||
}
|
||||
|
@ -19,23 +19,21 @@ type TextArea struct {
|
||||
CurrentBuffer *Buffer
|
||||
}
|
||||
|
||||
func CreateWindow(initialBuffer *Buffer) (*Window, error) {
|
||||
func CreateWindow() (*Window, error) {
|
||||
window := Window{
|
||||
ShowTopMenu: true,
|
||||
ShowLineIndex: true,
|
||||
|
||||
textArea: TextArea{
|
||||
CursorPos: 0,
|
||||
CurrentBuffer: initialBuffer,
|
||||
CurrentBuffer: nil,
|
||||
},
|
||||
|
||||
screen: nil,
|
||||
}
|
||||
|
||||
// Create empty buffer if nil
|
||||
if window.textArea.CurrentBuffer == nil {
|
||||
window.textArea.CurrentBuffer = CreateBuffer("New File")
|
||||
}
|
||||
window.textArea.CurrentBuffer = CreateBuffer("New File")
|
||||
|
||||
// Create tcell screen
|
||||
screen, err := tcell.NewScreen()
|
||||
|
Loading…
x
Reference in New Issue
Block a user