- lines := totalLines[topline:lineEnd]
- for y, line := range lines {
- for x, ch := range line {
- st := defStyle
- screen.SetContent(x, y, ch, nil, st)
- }
+ }
+}
+
+// VSplit opens a vertical split with file given in the first argument
+// If no file is given, it opens an empty buffer in a new split
+func VSplit(args []string) {
+ if len(args) == 0 {
+ CurView().VSplit(NewBuffer([]byte{}, ""))
+ } else {
+ filename := args[0]
+ home, _ := homedir.Dir()
+ filename = strings.Replace(filename, "~", home, 1)
+ file, err := ioutil.ReadFile(filename)
+
+ var buf *Buffer
+ if err != nil {
+ // File does not exist -- create an empty buffer with that name
+ buf = NewBuffer([]byte{}, filename)
+ } else {
+ buf = NewBuffer(file, filename)
+ }
+ CurView().VSplit(buf)
+ }
+}
+
+// HSplit opens a horizontal split with file given in the first argument
+// If no file is given, it opens an empty buffer in a new split
+func HSplit(args []string) {
+ if len(args) == 0 {
+ CurView().HSplit(NewBuffer([]byte{}, ""))
+ } else {
+ filename := args[0]
+ home, _ := homedir.Dir()
+ filename = strings.Replace(filename, "~", home, 1)
+ file, err := ioutil.ReadFile(filename)
+
+ var buf *Buffer
+ if err != nil {
+ // File does not exist -- create an empty buffer with that name
+ buf = NewBuffer([]byte{}, filename)
+ } else {
+ buf = NewBuffer(file, filename)