-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The tagline works similarly to acme, where you can use it as a scratch space for writing commands. It can be accessed with either the mouse pointer (like acme), or by typing ; or :. This allows it to double as something like a vi ex-mode as well as an acme tagline (though ex commands aren't implemented, someone could theoretically add a plugin which adds them.)
- Loading branch information
Showing
16 changed files
with
643 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
de |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package actions | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"github.com/driusan/de/demodel" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
func OpenFile(filename string, buff *demodel.CharBuffer) error { | ||
fstat, err := os.Stat(filename) | ||
if err != nil { | ||
return err | ||
} | ||
// file exists, so open it. | ||
switch fstat.IsDir() { | ||
case false: | ||
// it's a file | ||
|
||
b, ferr := ioutil.ReadFile(filename) | ||
if ferr != nil { | ||
fmt.Fprintf(os.Stderr, "%s\n", err) | ||
return ferr | ||
} | ||
|
||
oldFilename := buff.Filename | ||
buff.Buffer = b | ||
buff.Filename = filename | ||
buff.Dot.Start = 0 | ||
buff.Dot.End = 0 | ||
|
||
if buff.Tagline.Buffer == nil { | ||
buff.Tagline.Buffer = make([]byte, 0) | ||
} | ||
// if the tagline starts with the filename, update it, otherwise, | ||
// add it as a prefix. | ||
buff.Tagline.Buffer = append( | ||
[]byte(filename+" "), | ||
bytes.TrimPrefix(buff.Tagline.Buffer, []byte(oldFilename))..., | ||
) | ||
case true: | ||
// it's a directory | ||
files, err := ioutil.ReadDir(filename) | ||
if err != nil { | ||
return err | ||
} | ||
os.Chdir(filename) | ||
|
||
var bBuff bytes.Buffer | ||
fmt.Fprintf(&bBuff, "./\n../\n") | ||
|
||
for _, f := range files { | ||
|
||
if f.IsDir() { | ||
fmt.Fprintf(&bBuff, "%s/\n", f.Name()) | ||
} else { | ||
fmt.Fprintf(&bBuff, "%s\n", f.Name()) | ||
} | ||
} | ||
|
||
oldFilename := buff.Filename | ||
|
||
buff.Buffer = bBuff.Bytes() | ||
buff.Filename = filename | ||
buff.Dot.Start = 0 | ||
buff.Dot.End = 0 | ||
|
||
buff.Tagline.Buffer = append( | ||
[]byte(filename+" "), | ||
bytes.TrimPrefix(buff.Tagline.Buffer, []byte(oldFilename))..., | ||
) | ||
|
||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package demodel | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
var NoTagline = errors.New("No tagline exists for buffer") | ||
|
||
func (c *CharBuffer) AppendTag(val string) error { | ||
if c == nil || c.Tagline == nil { | ||
return NoTagline | ||
} | ||
|
||
c.Tagline.Buffer = append(c.Tagline.Buffer, []byte(val)...) | ||
return nil | ||
} | ||
|
||
func (c *CharBuffer) ResetTagline() error { | ||
c.Tagline = &CharBuffer{Buffer: []byte(c.Filename)} | ||
c.AppendTag(" | Save Discard Cut Copy Paste Exit") | ||
c.Tagline.Dot.Start = uint(len(c.Tagline.Buffer)) | ||
c.Tagline.Dot.End = c.Tagline.Dot.Start | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.