Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update to meet the requirements of Go1

  • Loading branch information...
commit f7c7f8aec7f885fc449f476732a417c24dbf2169 1 parent 7d394ce
@atom-symbol atom-symbol authored
View
14 GOAM.conf
@@ -1,14 +0,0 @@
-// Required compiler version
-MinCompilerVersion(6580)
-
-// Package
-Package("clingon")
-InstallPackage()
-
-// Dependencies
-
-makeInstall := make([]string, 2)
-makeInstall[0] = "make"
-makeInstall[1] = "install"
-RemotePackage("atom/sdl atom/sdl/ttf", "github", "0xe2-0x9a-0x9b/Go-SDL", makeInstall)
-RemotePackage("prettytest", "github", "remogatto/prettytest", makeInstall)
View
33 README.md
@@ -58,40 +58,13 @@ difficult to add more backends (e.g. opengl, draw/x11, etc.)
# Installation
-In order to use the SDL renderer, you should install the following
-packages (assuming a debian-flavored linux distribution):
-
- sudo apt-get install libsdl1.2-dev libsdl-mixer1.2-dev libsdl-image1.2-dev libsdl-ttf2.0-dev
-
-Clingon is using the GOAM build tool. To install it:
-
- goinstall github.com/0xe2-0x9a-0x9b/goam
- cd $GOROOT/src/pkg/github.com/0xe2-0x9a-0x9b/goam
- make install
-
-To install the dependencies and build the package:
-
- git clone https://github.com/remogatto/clingon.git
- cd clingon
- goam make
-
-To install (uninstall) clingon:
-
- goam install
- (goam uninstall)
-
-The following dependencies are installed automatically:
-
-* [⚛Go-SDL](https://github.com/0xe2-0x9a-0x9b/Go-SDL)
-* [prettytest](https://github.com/remogatto/prettytest)
-
-# Quick start
+ go get -v github.com/remogatto/clingon
After installing the package try the sample code in <tt>example/</tt>
folder:
- cd clingon
- example/shell -bg-image testdata/gopher.jpg testdata/VeraMono.ttf
+ cd $GOPATH/github.com/remogatto/clingon/example
+ make run
# TODO
View
4 animation.go
@@ -1,8 +1,8 @@
package clingon
import (
- "time"
"math"
+ "time"
)
const DEFAULT_ANIMATION_FPS = 30
@@ -47,7 +47,7 @@ func NewAnimation(f func(t float64) float64, length float64) *Animation {
func (animation *Animation) Start() {
if !animation.running {
// Note: the "+1" ensures that the argument to NewTicker is >= 1
- ticker := time.NewTicker(int64(1e9*animation.dt) + 1)
+ ticker := time.NewTicker(time.Duration(1e9*animation.dt) + 1)
go animation.animate(ticker)
animation.running = true
View
96 console.go
@@ -1,11 +1,9 @@
package clingon
import (
- "os"
- "time"
"strings"
- "container/vector"
"sync"
+ "time"
)
const (
@@ -22,7 +20,7 @@ const (
)
type Evaluator interface {
- Run(console *Console, command string) os.Error
+ Run(console *Console, command string) error
}
type Cmd_UpdateConsole struct {
@@ -47,12 +45,11 @@ type Renderer interface {
type commandLine struct {
prompt string
- // The content of the prompt line as a string vector
- content *vector.StringVector
+ // The prompt line as a string vector
+ content []string
- // The history of the command line.
- // This is a vector of '*vector.StringVector'.
- history vector.Vector
+ // The history of the command line
+ history [][]string
// Cursor position on current line
cursorPosition int
@@ -60,18 +57,10 @@ type commandLine struct {
historyPosition int
}
-func stringVectorToString(v *vector.StringVector) string {
- var currLine string
- for _, str := range *v {
- currLine += str
- }
- return currLine
-}
-
func newCommandLine(prompt string) *commandLine {
return &commandLine{
prompt: prompt,
- content: new(vector.StringVector),
+ content: nil,
cursorPosition: 0,
historyPosition: 0,
}
@@ -88,7 +77,12 @@ func (commandLine *commandLine) empty() bool {
// Insert a string in the prompt line
func (commandLine *commandLine) insertChar(str string) {
- commandLine.content.Insert(commandLine.cursorPosition, str)
+ // Insert 'str' at commandLine.cursorPosition
+ commandLine.content = append(commandLine.content, "")
+ pos := commandLine.cursorPosition
+ copy(commandLine.content[pos+1:], commandLine.content[pos:])
+ commandLine.content[pos] = str
+
commandLine.incCursorPosition(len(str))
}
@@ -96,22 +90,29 @@ func (commandLine *commandLine) insertChar(str string) {
func (commandLine *commandLine) key_backspace() {
if commandLine.cursorPosition >= 1 {
commandLine.decCursorPosition(1)
- commandLine.content.Delete(commandLine.cursorPosition)
+
+ // Delete the element at 'commandLine.cursorPosition'
+ pos := commandLine.cursorPosition
+ copy(commandLine.content[pos:], commandLine.content[pos+1:])
+ commandLine.content = commandLine.content[0 : len(commandLine.content)-1]
}
}
// Delete the character at the current cursor position
func (commandLine *commandLine) key_delete() {
- if commandLine.cursorPosition < commandLine.content.Len() {
- commandLine.content.Delete(commandLine.cursorPosition)
+ if commandLine.cursorPosition < len(commandLine.content) {
+ // Delete the element at 'commandLine.cursorPosition'
+ pos := commandLine.cursorPosition
+ copy(commandLine.content[pos:], commandLine.content[pos+1:])
+ commandLine.content = commandLine.content[0 : len(commandLine.content)-1]
}
}
// Clear the prompt line
func (commandLine *commandLine) clear() {
- commandLine.content = new(vector.StringVector)
+ commandLine.content = []string(nil)
commandLine.cursorPosition = 0
- commandLine.historyPosition = commandLine.history.Len()
+ commandLine.historyPosition = len(commandLine.history)
}
// Browse history on the command line
@@ -125,19 +126,21 @@ func (commandLine *commandLine) browseHistory(direction int) {
commandLine.historyPosition = 0
return
}
- if commandLine.historyPosition >= commandLine.history.Len() {
+ if commandLine.historyPosition >= len(commandLine.history) {
commandLine.clear()
return
}
- newContent := commandLine.history.At(commandLine.historyPosition).(*vector.StringVector).Copy()
- commandLine.content = &newContent
+
+ var newContent []string
+ newContent = append(newContent, commandLine.history[commandLine.historyPosition]...)
+ commandLine.content = newContent
commandLine.incCursorPosition(len(commandLine.toString()))
}
// Push current command line on the history and reset the history counter
func (commandLine *commandLine) push() string {
if commandLine.contentToString() != "" && commandLine.notInHistory(commandLine.contentToString()) {
- commandLine.history.Push(commandLine.content)
+ commandLine.history = append(commandLine.history, commandLine.content)
}
line := commandLine.contentToString()
commandLine.clear()
@@ -159,7 +162,7 @@ func (commandLine *commandLine) moveCursor(dir int) {
}
func (commandLine *commandLine) contentToString() string {
- return stringVectorToString(commandLine.content)
+ return strings.Join(commandLine.content, "")
}
func (commandLine *commandLine) decCursorPosition(dec int) {
@@ -171,15 +174,14 @@ func (commandLine *commandLine) decCursorPosition(dec int) {
func (commandLine *commandLine) incCursorPosition(inc int) {
commandLine.cursorPosition += inc
- if commandLine.cursorPosition > commandLine.content.Len() {
- commandLine.cursorPosition = commandLine.content.Len()
+ if commandLine.cursorPosition > len(commandLine.content) {
+ commandLine.cursorPosition = len(commandLine.content)
}
}
func (commandLine *commandLine) notInHistory(line string) bool {
- for _, v := range commandLine.history {
- strVector := v.(*vector.StringVector)
- historyEntry := stringVectorToString(strVector)
+ for _, h := range commandLine.history {
+ historyEntry := strings.Join(h, "")
if line == historyEntry {
return false
}
@@ -188,8 +190,8 @@ func (commandLine *commandLine) notInHistory(line string) bool {
}
type Console struct {
- commandLine *commandLine // An instance of the commandline
- lines *vector.StringVector // Lines of text above the commandline
+ commandLine *commandLine // An instance of the commandline
+ lines []string // Lines of text above the commandline
renderer_orNil Renderer
evaluator_orNil Evaluator
mu sync.RWMutex
@@ -198,7 +200,7 @@ type Console struct {
// Initialize a new console object passing to it an evaluator
func NewConsole(evaluator_orNil Evaluator) *Console {
console := &Console{
- lines: new(vector.StringVector),
+ lines: []string(nil),
commandLine: newCommandLine("console> "),
renderer_orNil: nil,
evaluator_orNil: evaluator_orNil,
@@ -229,9 +231,8 @@ func (console *Console) SetRenderer(renderer_orNil Renderer) {
// Dump the console content as a string.
func (console *Console) String() string {
var result string
- for _, str := range *console.lines {
- result += str + "\n"
- }
+ result += strings.Join(console.lines, "\n")
+ result += "\n"
result += console.commandLine.toString()
return result
}
@@ -245,7 +246,7 @@ func (console *Console) SetPrompt(prompt string) {
// The strings should not contain '\n'.
func (console *Console) PrintLines(strings []string) {
if len(strings) > 0 {
- console.pushLines(strings)
+ console.appendLines(strings)
}
console.mu.RLock()
@@ -293,7 +294,7 @@ func (console *Console) PutUnicode(value uint16) {
command := console.carriageReturn()
if console.evaluator_orNil != nil {
if err := console.evaluator_orNil.Run(console, command); err != nil {
- console.Print(err.String())
+ console.Print(err.Error())
}
}
event = Cmd_UpdateConsole{console}
@@ -357,19 +358,16 @@ func (console *Console) ClearCommandline() {
}
}
-// Push lines of text on the console. The argument is a slice of
-// strings.
-func (console *Console) pushLines(lines []string) {
- for _, line := range lines {
- console.lines.Push(line)
- }
+// Push lines of text on the console
+func (console *Console) appendLines(lines []string) {
+ console.lines = append(console.lines, lines...)
}
// Push the current commandline in the console history.
// Return it as a string.
func (console *Console) carriageReturn() string {
commandLine := console.commandLine.push()
- console.lines.Push(console.commandLine.prompt + commandLine)
+ console.lines = append(console.lines, console.commandLine.prompt+commandLine)
return commandLine
}
View
28 console_test.go
@@ -1,8 +1,8 @@
package clingon
import (
+ pt "github.com/remogatto/prettytest"
"testing"
- pt "prettytest"
)
var console *Console
@@ -49,34 +49,34 @@ func (s *consoleTestSuite) TestString() {
}
func (s *consoleTestSuite) TestPutUnicode() {
- console.PutUnicode(uint16([]int("a")[0]))
- console.PutUnicode(uint16([]int("b")[0]))
- console.PutUnicode(uint16([]int("c")[0]))
- s.Equal("a", console.commandLine.content.At(0))
- s.Equal("b", console.commandLine.content.At(1))
- s.Equal("c", console.commandLine.content.At(2))
+ console.PutUnicode('a')
+ console.PutUnicode('b')
+ console.PutUnicode('c')
+ s.Equal("a", console.commandLine.content[0])
+ s.Equal("b", console.commandLine.content[1])
+ s.Equal("c", console.commandLine.content[2])
s.Equal(3, console.commandLine.cursorPosition)
}
func (s *consoleTestSuite) TestPrint() {
console.Print("foo\nbar\nbaz")
- s.Equal("foo", console.lines.At(0))
- s.Equal("bar", console.lines.At(1))
- s.Equal("baz", console.lines.At(2))
+ s.Equal("foo", console.lines[0])
+ s.Equal("bar", console.lines[1])
+ s.Equal("baz", console.lines[2])
s.Equal("console> ", console.commandLine.toString())
}
func (s *consoleTestSuite) TestPrintLines() {
console.PrintLines([]string{"foo", "bar", "baz"})
- s.Equal("foo", console.lines.At(0))
- s.Equal("bar", console.lines.At(1))
- s.Equal("baz", console.lines.At(2))
+ s.Equal("foo", console.lines[0])
+ s.Equal("bar", console.lines[1])
+ s.Equal("baz", console.lines[2])
s.Equal("console> ", console.commandLine.toString())
}
func (s *consoleTestSuite) TestPutCommand() {
console.PutCommand("foo")
- s.Equal("console> foo", console.lines.At(0))
+ s.Equal("console> foo", console.lines[0])
}
func (s *consoleTestSuite) TestPutString() {
View
1  example/GOAM.conf
@@ -1 +0,0 @@
-Executable("shell", "shell.go evaluator.go")
View
8 example/Makefile
@@ -0,0 +1,8 @@
+shell: *.go
+ go build -o shell
+
+run: shell
+ ./shell -bg-image=gopher.jpg VeraMono.ttf
+
+clean:
+ go clean
View
0  testdata/VeraMono.ttf → example/VeraMono.ttf
File renamed without changes
View
6 example/evaluator.go
@@ -2,14 +2,14 @@ package main
import (
"bytes"
- "exec"
+ "github.com/remogatto/clingon"
"os"
- "clingon"
+ "os/exec"
)
type ShellEvaluator struct{}
-func (eval *ShellEvaluator) Run(console *clingon.Console, command string) os.Error {
+func (eval *ShellEvaluator) Run(console *clingon.Console, command string) error {
var buf bytes.Buffer
cmd := exec.Command(os.Getenv("SHELL"), "-c", command)
View
0  testdata/gopher.jpg → example/gopher.jpg
File renamed without changes
View
11 example/shell.go
@@ -1,12 +1,12 @@
package main
import (
- "atom/sdl"
- "atom/sdl/ttf"
- "fmt"
"flag"
+ "fmt"
+ "github.com/0xe2-0x9a-0x9b/Go-SDL/sdl"
+ "github.com/0xe2-0x9a-0x9b/Go-SDL/ttf"
+ "github.com/remogatto/clingon"
"os"
- "clingon"
)
var (
@@ -84,7 +84,8 @@ func initialize(config *configuration) *renderer {
sdl.EnableUNICODE(1)
if config.fullscreen {
- appSurface = sdl.SetVideoMode(640, 480, 32, sdl.FULLSCREEN)
+ flags := sdl.FULLSCREEN
+ appSurface = sdl.SetVideoMode(640, 480, 32, uint32(flags))
sdl.ShowCursor(sdl.DISABLE)
} else {
appSurface = sdl.SetVideoMode(640, 480, 32, 0)
View
10 sdlrenderer.go
@@ -1,8 +1,8 @@
package clingon
import (
- "atom/sdl"
- "atom/sdl/ttf"
+ "github.com/0xe2-0x9a-0x9b/Go-SDL/sdl"
+ "github.com/0xe2-0x9a-0x9b/Go-SDL/ttf"
"unsafe"
)
@@ -119,7 +119,7 @@ func (renderer *SDLRenderer) calcCommandLineRect() {
}
func (renderer *SDLRenderer) resizeInternalSurface(console *Console) {
- h := uint(console.lines.Len()+1) * renderer.fontHeight
+ h := uint(len(console.lines)+1) * renderer.fontHeight
if h > renderer.internalSurfaceMaxHeight {
h = renderer.internalSurfaceMaxHeight
}
@@ -145,9 +145,9 @@ func (renderer *SDLRenderer) renderCommandLine(commandLine *commandLine) {
func (renderer *SDLRenderer) renderConsole(console *Console) {
renderer.resizeInternalSurface(console)
- for i := console.lines.Len(); i > 0; i-- {
+ for i := len(console.lines); i > 0; i-- {
if uint(i) < renderer.lastVisibleLine {
- renderer.renderLine(i, console.lines.At(console.lines.Len()-i))
+ renderer.renderLine(i, console.lines[len(console.lines)-i])
} else {
continue
}
View
8 sdlrenderer_benchmark_test.go
@@ -1,9 +1,9 @@
package clingon
import (
- "atom/sdl"
- "atom/sdl/ttf"
"fmt"
+ "github.com/0xe2-0x9a-0x9b/Go-SDL/sdl"
+ "github.com/0xe2-0x9a-0x9b/Go-SDL/ttf"
"testing"
)
@@ -63,7 +63,7 @@ func BenchmarkRenderConsoleBlended(b *testing.B) {
for i := 0; i < 1000; i++ {
strings = append(strings, fmt.Sprintf("Line %d %s", i, "The quick brown fox jumps over the lazy dog"))
}
- console.pushLines(strings)
+ console.appendLines(strings)
sdlrenderer.Blended = true
b.StartTimer()
for i := 0; i < b.N; i++ {
@@ -79,7 +79,7 @@ func BenchmarkRenderConsoleSolid(b *testing.B) {
for i := 0; i < 1000; i++ {
strings = append(strings, fmt.Sprintf("Line %d %s", i, "The quick brown fox jumps over the lazy dog"))
}
- console.pushLines(strings)
+ console.appendLines(strings)
b.StartTimer()
for i := 0; i < b.N; i++ {
sdlrenderer.renderConsole(console)
View
2  specs/GOAM.conf
@@ -1,2 +0,0 @@
-// Package name
-Package("clingon/specs")
View
8 specs/clingon_test.go
@@ -1,11 +1,11 @@
package specs
import (
- "atom/sdl"
- "testing"
- pt "prettytest"
"fmt"
- "clingon"
+ "github.com/0xe2-0x9a-0x9b/Go-SDL/sdl"
+ "github.com/remogatto/clingon"
+ pt "github.com/remogatto/prettytest"
+ "testing"
"time"
)
View
21 specs/specs.go
@@ -1,11 +1,10 @@
package specs
import (
- "atom/sdl"
- "atom/sdl/ttf"
+ "github.com/0xe2-0x9a-0x9b/Go-SDL/sdl"
+ "github.com/0xe2-0x9a-0x9b/Go-SDL/ttf"
+ "github.com/remogatto/clingon"
"time"
- "clingon"
- "os"
)
const (
@@ -39,7 +38,7 @@ type NewAnimation struct {
type Echoer struct{}
-func (e *Echoer) Run(console *clingon.Console, command string) os.Error {
+func (e *Echoer) Run(console *clingon.Console, command string) error {
console.Print(command)
return nil
}
@@ -51,10 +50,10 @@ type Interactor interface {
type EnterCommand struct {
console *clingon.Console
command string
- time int64
+ time time.Duration
}
-func NewEnterCommand(console *clingon.Console, command string, time int64) *EnterCommand {
+func NewEnterCommand(console *clingon.Console, command string, time time.Duration) *EnterCommand {
return &EnterCommand{console, command + "\u000d", time}
}
@@ -71,10 +70,10 @@ func (i *EnterCommand) Interact(done chan bool) {
type BrowseHistory struct {
console *clingon.Console
dirs []int
- time int64
+ time time.Duration
}
-func NewBrowseHistory(console *clingon.Console, dirs []int, time int64) *BrowseHistory {
+func NewBrowseHistory(console *clingon.Console, dirs []int, time time.Duration) *BrowseHistory {
return &BrowseHistory{console, dirs, time}
}
func (i *BrowseHistory) Interact(done chan bool) {
@@ -90,10 +89,10 @@ func (i *BrowseHistory) Interact(done chan bool) {
type MoveCursor struct {
console *clingon.Console
dirs []int
- time int64
+ time time.Duration
}
-func NewMoveCursor(console *clingon.Console, dirs []int, time int64) *MoveCursor {
+func NewMoveCursor(console *clingon.Console, dirs []int, time time.Duration) *MoveCursor {
return &MoveCursor{console, dirs, time}
}
func (i *MoveCursor) Interact(done chan bool) {
Please sign in to comment.
Something went wrong with that request. Please try again.