Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: edsrzf/fineline
base: 3e1f28de77
...
head fork: edsrzf/fineline
compare: d0b140e086
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 11 files changed
  • 0 commit comments
  • 1 contributor
View
5 .gitignore
@@ -0,0 +1,5 @@
+[a568].out
+*.[568ao]
+*.swp
+_*
+testdata
View
28 Makefile
@@ -1,28 +0,0 @@
-# Copyright 2011 The Go Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file.
-
-include $(GOROOT)/src/Make.inc
-
-TARG=github.com/edsrzf/fineline
-
-GOFILES=\
- buffer.go\
- completer.go\
- fineline.go\
- ops.go\
- termios.go\
-
-GOFILES_linux=\
- ansi.go\
- ioctl.go\
-
-GOFILES_windows=\
- windows.go\
-
-GOFILES+=$(GOFILES_$(GOOS))
-
-include $(GOROOT)/src/Make.pkg
-
-termios.go: defs.c
- godefs -g fineline defs.c > termios.go
View
3  README.md
@@ -4,4 +4,5 @@ fineline
fineline is a line editing package for the [Go programming language](http://golang.org).
It's written entirely in Go; it doesn't wrap readline, libedit, or anything else.
-This is still pretty experimental and probably has bugs. Windows support is partially working, but still has some kinks to work out.
+This is still pretty experimental and buggy. Windows support is partially
+working, but still has some kinks to work out.
View
9 buffer.go
@@ -1,9 +1,6 @@
package fineline
-import (
- "os"
- "utf8"
-)
+import "unicode/utf8"
// This is similar to bytes.Buffer, but it has random access
type buffer struct {
@@ -70,14 +67,14 @@ func (b *buffer) Write(p []byte, pos int) {
copy(b.buf[pos:], p)
}
-func (b *buffer) WriteByte(c byte, pos int) os.Error {
+func (b *buffer) WriteByte(c byte, pos int) error {
b.grow(1)
copy(b.buf[pos+1:], b.buf[pos:])
b.buf[pos] = c
return nil
}
-func (b *buffer) WriteRune(r int, pos int) {
+func (b *buffer) WriteRune(r rune, pos int) {
if r < utf8.RuneSelf {
b.WriteByte(byte(r), pos)
return
View
12 completer.go
@@ -130,20 +130,20 @@ func (c *FilenameCompleter) Complete(str string, cur int) []string {
}
dir, err := os.Open(dirPath)
if err != nil {
- panic(err.String())
+ panic(err.Error())
}
defer dir.Close()
var candidates []string
names, err := dir.Readdir(-1)
if err != nil {
- panic(err.String())
+ panic(err.Error())
}
for _, f := range names {
- if strings.HasPrefix(f.Name, prefix) {
- if f.IsDirectory() {
- candidates = append(candidates, f.Name + "/")
+ if strings.HasPrefix(f.Name(), prefix) {
+ if f.IsDir() {
+ candidates = append(candidates, f.Name() + "/")
} else {
- candidates = append(candidates, f.Name)
+ candidates = append(candidates, f.Name())
}
}
}
View
77 defs.c
@@ -1,77 +0,0 @@
-#include <termios.h>
-#include <sys/ioctl.h>
-
-enum {
- $TCGETS = TCGETS,
- $TCSETS = TCSETS,
- $TCSETSW = TCSETSW,
- $TCSETSF = TCSETSF,
- $TIOCGWINSZ = TIOCGWINSZ,
-
- /* c_iflag bits */
- $IGNBRK = IGNBRK,
- $BRKINT = BRKINT,
- $IGNPAR = IGNPAR,
- $PARMRK = PARMRK,
- $INPCK = INPCK,
- $ISTRIP = ISTRIP,
- $INLCR = INLCR,
- $IGNCR = IGNCR,
- $ICRNL = ICRNL,
- $IUCLC = IUCLC,
- $IXON = IXON,
- $IXANY = IXANY,
- $IXOFF = IXOFF,
- $IMAXBEL = IMAXBEL,
- $IUTF8 = IUTF8,
-
- /* c_oflag bits */
- $OPOST = OPOST,
- $OLCUC = OLCUC,
- $ONLCR = ONLCR,
- $OCRNL = OCRNL,
- $ONOCR = ONOCR,
- $ONLRET = ONLRET,
- $OFILL = OFILL,
- $OFDEL = OFDEL,
-
- $CS8 = CS8,
-
- /* c_lflag bits */
- $ISIG = ISIG,
- $ICANON = ICANON,
- $ECHO = ECHO,
- $ECHOE = ECHOE,
- $ECHOK = ECHOK,
- $ECHONL = ECHONL,
- $NOFLSH = NOFLSH,
- $TOSTOP = TOSTOP,
- $IEXTEN = IEXTEN,
-
- /* c_cc characters */
- $VINTR = VINTR,
- $VQUIT = VQUIT,
- $VERASE = VERASE,
- $VKILL = VKILL,
- $VEOF = VEOF,
- $VTIME = VTIME,
- $VMIN = VMIN,
- $VSWTC = VSWTC,
- $VSTART = VSTART,
- $VSTOP = VSTOP,
- $VSUSP = VSUSP,
- $VEOL = VEOL,
- $VREPRINT = VREPRINT,
- $VDISCARD = VDISCARD,
- $VWERASE = VWERASE,
- $VLNEXT = VLNEXT,
- $VEOL2 = VEOL2,
-
- /* tcsetattr uses these */
- $TCSANOW = TCSANOW,
- $TCSADRAIN = TCSADRAIN,
- $TCSAFLUSH = TCSAFLUSH,
-};
-
-typedef struct termios $termios;
-typedef struct winsize $winsize;
View
84 defs.go
@@ -0,0 +1,84 @@
+// +build ignore
+
+package fineline
+
+/*
+#include <termios.h>
+#include <sys/ioctl.h>
+*/
+import "C"
+
+const (
+ TCGETS = C.TCGETS
+ TCSETS = C.TCSETS
+ TCSETSW = C.TCSETSW
+ TCSETSF = C.TCSETSF
+ TIOCGWINSZ = C.TIOCGWINSZ
+
+ /* c_iflag bits */
+ IGNBRK = C.IGNBRK
+ BRKINT = C.BRKINT
+ IGNPAR = C.IGNPAR
+ PARMRK = C.PARMRK
+ INPCK = C.INPCK
+ ISTRIP = C.ISTRIP
+ INLCR = C.INLCR
+ IGNCR = C.IGNCR
+ ICRNL = C.ICRNL
+ IUCLC = C.IUCLC
+ IXON = C.IXON
+ IXANY = C.IXANY
+ IXOFF = C.IXOFF
+ IMAXBEL = C.IMAXBEL
+ IUTF8 = C.IUTF8
+
+ /* c_oflag bits */
+ OPOST = C.OPOST
+ OLCUC = C.OLCUC
+ ONLCR = C.ONLCR
+ OCRNL = C.OCRNL
+ ONOCR = C.ONOCR
+ ONLRET = C.ONLRET
+ OFILL = C.OFILL
+ OFDEL = C.OFDEL
+
+ CS8 = C.CS8
+
+ /* c_lflag bits */
+ ISIG = C.ISIG
+ ICANON = C.ICANON
+ ECHO = C.ECHO
+ ECHOE = C.ECHOE
+ ECHOK = C.ECHOK
+ ECHONL = C.ECHONL
+ NOFLSH = C.NOFLSH
+ TOSTOP = C.TOSTOP
+ IEXTEN = C.IEXTEN
+
+ /* c_cc characters */
+ VINTR = C.VINTR
+ VQUIT = C.VQUIT
+ VERASE = C.VERASE
+ VKILL = C.VKILL
+ VEOF = C.VEOF
+ VTIME = C.VTIME
+ VMIN = C.VMIN
+ VSWTC = C.VSWTC
+ VSTART = C.VSTART
+ VSTOP = C.VSTOP
+ VSUSP = C.VSUSP
+ VEOL = C.VEOL
+ VREPRINT = C.VREPRINT
+ VDISCARD = C.VDISCARD
+ VWERASE = C.VWERASE
+ VLNEXT = C.VLNEXT
+ VEOL2 = C.VEOL2
+
+ /* tcsetattr uses these */
+ TCSANOW = C.TCSANOW
+ TCSADRAIN = C.TCSADRAIN
+ TCSAFLUSH = C.TCSAFLUSH
+)
+
+type termios C.struct_termios
+type winsize C.struct_winsize
View
89 defs_linux_amd64.go
@@ -0,0 +1,89 @@
+// Created by cgo -godefs - DO NOT EDIT
+// cgo -godefs defs.go
+
+package fineline
+
+const (
+ TCGETS = 0x5401
+ TCSETS = 0x5402
+ TCSETSW = 0x5403
+ TCSETSF = 0x5404
+ TIOCGWINSZ = 0x5413
+
+ IGNBRK = 0x1
+ BRKINT = 0x2
+ IGNPAR = 0x4
+ PARMRK = 0x8
+ INPCK = 0x10
+ ISTRIP = 0x20
+ INLCR = 0x40
+ IGNCR = 0x80
+ ICRNL = 0x100
+ IUCLC = 0x200
+ IXON = 0x400
+ IXANY = 0x800
+ IXOFF = 0x1000
+ IMAXBEL = 0x2000
+ IUTF8 = 0x4000
+
+ OPOST = 0x1
+ OLCUC = 0x2
+ ONLCR = 0x4
+ OCRNL = 0x8
+ ONOCR = 0x10
+ ONLRET = 0x20
+ OFILL = 0x40
+ OFDEL = 0x80
+
+ CS8 = 0x30
+
+ ISIG = 0x1
+ ICANON = 0x2
+ ECHO = 0x8
+ ECHOE = 0x10
+ ECHOK = 0x20
+ ECHONL = 0x40
+ NOFLSH = 0x80
+ TOSTOP = 0x100
+ IEXTEN = 0x8000
+
+ VINTR = 0x0
+ VQUIT = 0x1
+ VERASE = 0x2
+ VKILL = 0x3
+ VEOF = 0x4
+ VTIME = 0x5
+ VMIN = 0x6
+ VSWTC = 0x7
+ VSTART = 0x8
+ VSTOP = 0x9
+ VSUSP = 0xa
+ VEOL = 0xb
+ VREPRINT = 0xc
+ VDISCARD = 0xd
+ VWERASE = 0xe
+ VLNEXT = 0xf
+ VEOL2 = 0x10
+
+ TCSANOW = 0x0
+ TCSADRAIN = 0x1
+ TCSAFLUSH = 0x2
+)
+
+type termios struct {
+ Iflag uint32
+ Oflag uint32
+ Cflag uint32
+ Lflag uint32
+ Line uint8
+ Cc [32]uint8
+ Pad_cgo_0 [3]byte
+ Ispeed uint32
+ Ospeed uint32
+}
+type winsize struct {
+ Row uint16
+ Col uint16
+ Xpixel uint16
+ Ypixel uint16
+}
View
18 fineline.go
@@ -10,15 +10,15 @@ import (
type termCommon struct {
prompt string
- buf *buffer
+ buf *buffer
// number of lines we last wrote
- lines int
+ lines int
pos, cols int
- c Completer
+ c Completer
// candidates from last tab completion
candidates []string
- display bool
- y int
+ display bool
+ y int
}
// A circular array of history
@@ -58,7 +58,7 @@ func unsupportedTerm() bool {
return false
}
-func Read(prompt string, c Completer) (line string, err os.Error) {
+func Read(prompt string, c Completer) (line string, err error) {
// TODO: Check if STDIN is a TTY
if unsupportedTerm() {
// Fall back to plain old stdin reading
@@ -74,10 +74,10 @@ func Read(prompt string, c Completer) (line string, err os.Error) {
return
}
-func (t *term) getLine() (string, os.Error) {
+func (t *term) getLine() (string, error) {
r := bufio.NewReader(os.Stdin)
t.refreshLine()
- var err os.Error
+ var err error
cont := true
for cont && err == nil {
c, _, err := r.ReadRune()
@@ -85,7 +85,7 @@ func (t *term) getLine() (string, os.Error) {
return "", err
}
var op int
- if c < len(keyMap) {
+ if int(c) < len(keyMap) {
op = keyMap[c]
} else {
op = opPutc
View
71 ops.go
@@ -2,8 +2,9 @@ package fineline
import (
"bufio"
+ "errors"
"fmt"
- "os"
+ "io"
"strings"
)
@@ -32,40 +33,40 @@ const (
noop
)
-var keyMap = [...]int {
- 1: opHome, // ctrl-a
- 2: opLeft, // ctrl-b
- 3: opCancel, // ctrl-c
- 4: opEof, // ctrl-d
- 5: opEnd, // ctrl-e
- 6: opRight, // ctrl-f
- 7: noop, // ctrl-g
- 8: opBackspace, // ctrl-h
+var keyMap = [...]int{
+ 1: opHome, // ctrl-a
+ 2: opLeft, // ctrl-b
+ 3: opCancel, // ctrl-c
+ 4: opEof, // ctrl-d
+ 5: opEnd, // ctrl-e
+ 6: opRight, // ctrl-f
+ 7: noop, // ctrl-g
+ 8: opBackspace, // ctrl-h
'\t': opComplete,
'\r': opSubmit,
- 11: opDeleteToEnd, // ctrl-k
- 12: opClear, // ctrl-l
+ 11: opDeleteToEnd, // ctrl-k
+ 12: opClear, // ctrl-l
'\n': opSubmit,
- 14: noop, // ctrl-n
- 15: opSubmit, // ctrl-o
- 16: opUp, // ctrl-p
- 17: noop, // ctrl-q; should be quoted insert
- 18: noop, // ctrl-r; should be reverse history search
- 19: noop, // ctrl-s; should be forward history search?
- 20: opTranspose, // ctrl-t
- 21: opDeleteToBeginning, // ctrl-u
- 22: noop, // ctrl-v; should be quoted insert
- 23: noop, // ctrl-w; should be kill word
- 24: noop, // ctrl-x; should be something?
- 25: noop, // ctrl-y; should be yank
- 26: noop, // ctrl-z
- 27: opEscape,
- 127: opBackspace,
+ 14: noop, // ctrl-n
+ 15: opSubmit, // ctrl-o
+ 16: opUp, // ctrl-p
+ 17: noop, // ctrl-q; should be quoted insert
+ 18: noop, // ctrl-r; should be reverse history search
+ 19: noop, // ctrl-s; should be forward history search?
+ 20: opTranspose, // ctrl-t
+ 21: opDeleteToBeginning, // ctrl-u
+ 22: noop, // ctrl-v; should be quoted insert
+ 23: noop, // ctrl-w; should be kill word
+ 24: noop, // ctrl-x; should be something?
+ 25: noop, // ctrl-y; should be yank
+ 26: noop, // ctrl-z
+ 27: opEscape,
+ 127: opBackspace,
}
-var cancelled = os.NewError("line cancelled")
+var cancelled = errors.New("line cancelled")
-func (t *term) exec(r *bufio.Reader, op, c int) (bool, os.Error) {
+func (t *term) exec(r *bufio.Reader, op int, c rune) (bool, error) {
switch op {
case opPutc:
t.putc(c)
@@ -76,11 +77,11 @@ func (t *term) exec(r *bufio.Reader, op, c int) (bool, os.Error) {
case opCancel:
return false, cancelled
case opEof:
- if t.pos < t.buf.len() - 1 {
+ if t.pos < t.buf.len()-1 {
t.delete()
break
}
- return false, os.EOF
+ return false, io.EOF
case opEnd:
t.end()
case opRight:
@@ -160,7 +161,7 @@ func (t *term) exec(r *bufio.Reader, op, c int) (bool, os.Error) {
return true, nil
}
-func (t *term) putc(c int) {
+func (t *term) putc(c rune) {
t.buf.WriteRune(c, t.pos)
t.pos++
t.refreshLine()
@@ -298,13 +299,13 @@ func (t *term) refreshLine() {
bufStr := t.buf.String()
n := len(bufStr)
pl := len(t.prompt)
- if n > t.cols - pl {
+ if n > t.cols-pl {
n = t.cols - pl
}
fmt.Print(bufStr[:n])
bufStr = bufStr[n:]
t.lines = 0
- wrapCursor := n == t.cols - pl
+ wrapCursor := n == t.cols-pl
n = len(bufStr)
for n > 0 {
if n > t.cols {
@@ -324,5 +325,5 @@ func (t *term) refreshLine() {
}
x := (pl + t.pos) % t.cols
t.y = (pl + t.pos) / t.cols
- t.setCursor(x, t.y - t.lines)
+ t.setCursor(x, t.y-t.lines)
}
View
88 termios.go
@@ -1,88 +0,0 @@
-// godefs -g fineline defs.c
-
-// MACHINE GENERATED - DO NOT EDIT.
-
-package fineline
-
-// Constants
-const (
- TCGETS = 0x5401
- TCSETS = 0x5402
- TCSETSW = 0x5403
- TCSETSF = 0x5404
- TIOCGWINSZ = 0x5413
- IGNBRK = 0x1
- BRKINT = 0x2
- IGNPAR = 0x4
- PARMRK = 0x8
- INPCK = 0x10
- ISTRIP = 0x20
- INLCR = 0x40
- IGNCR = 0x80
- ICRNL = 0x100
- IUCLC = 0x200
- IXON = 0x400
- IXANY = 0x800
- IXOFF = 0x1000
- IMAXBEL = 0x2000
- IUTF8 = 0x4000
- OPOST = 0x1
- OLCUC = 0x2
- ONLCR = 0x4
- OCRNL = 0x8
- ONOCR = 0x10
- ONLRET = 0x20
- OFILL = 0x40
- OFDEL = 0x80
- CS8 = 0x30
- ISIG = 0x1
- ICANON = 0x2
- ECHO = 0x8
- ECHOE = 0x10
- ECHOK = 0x20
- ECHONL = 0x40
- NOFLSH = 0x80
- TOSTOP = 0x100
- IEXTEN = 0x8000
- VINTR = 0
- VQUIT = 0x1
- VERASE = 0x2
- VKILL = 0x3
- VEOF = 0x4
- VTIME = 0x5
- VMIN = 0x6
- VSWTC = 0x7
- VSTART = 0x8
- VSTOP = 0x9
- VSUSP = 0xa
- VEOL = 0xb
- VREPRINT = 0xc
- VDISCARD = 0xd
- VWERASE = 0xe
- VLNEXT = 0xf
- VEOL2 = 0x10
- TCSANOW = 0
- TCSADRAIN = 0x1
- TCSAFLUSH = 0x2
-)
-
-// Types
-
-type termios struct {
- Iflag uint32
- Oflag uint32
- Cflag uint32
- Lflag uint32
- Line uint8
- Cc [32]uint8
- Pad_godefs_0 [3]byte
- Ispeed uint32
- Ospeed uint32
-}
-
-type winsize struct {
- Row uint16
- Col uint16
- Xpixel uint16
- Ypixel uint16
-}

No commit comments for this range

Something went wrong with that request. Please try again.