mirror of
https://github.com/felixangell/phi.git
synced 2024-09-11 15:55:25 +03:00
comments and name style changes
This commit is contained in:
parent
4fdfe4141e
commit
2cd7c8495e
@ -100,8 +100,8 @@ func pageDown(v *View, commands []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
buff.scrollDown(DEFAULT_SCROLL_AMOUNT)
|
||||
for i := 0; i < DEFAULT_SCROLL_AMOUNT; i++ {
|
||||
buff.scrollDown(DefaultScrollAmount)
|
||||
for i := 0; i < DefaultScrollAmount; i++ {
|
||||
buff.moveDown()
|
||||
}
|
||||
return false
|
||||
@ -116,8 +116,8 @@ func pageUp(v *View, commands []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
buff.scrollUp(DEFAULT_SCROLL_AMOUNT)
|
||||
for i := 0; i < DEFAULT_SCROLL_AMOUNT; i++ {
|
||||
buff.scrollUp(DefaultScrollAmount)
|
||||
for i := 0; i < DefaultScrollAmount; i++ {
|
||||
buff.moveUp()
|
||||
}
|
||||
return false
|
||||
|
@ -21,14 +21,14 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
timer int64 = 0
|
||||
reset_timer int64 = 0
|
||||
should_draw bool = true
|
||||
should_flash bool
|
||||
timer = 0
|
||||
resetTimer = 0
|
||||
shouldDraw = true
|
||||
shouldFlash = false
|
||||
)
|
||||
|
||||
const (
|
||||
DEFAULT_SCROLL_AMOUNT = 10
|
||||
DefaultScrollAmount = 10
|
||||
)
|
||||
|
||||
// TODO move into config
|
||||
@ -43,6 +43,7 @@ type camera struct {
|
||||
dy int
|
||||
}
|
||||
|
||||
// AutoCompleteBox ...
|
||||
// TODO maybe have a thread that finds
|
||||
// words in the current file
|
||||
// and adds them to the vocabulary.
|
||||
@ -124,6 +125,8 @@ type BufferConfig struct {
|
||||
font *strife.Font
|
||||
}
|
||||
|
||||
// Buffer is a structure representing
|
||||
// a buffer of text.
|
||||
type Buffer struct {
|
||||
BaseComponent
|
||||
index int
|
||||
@ -140,6 +143,7 @@ type Buffer struct {
|
||||
autoComplete *AutoCompleteBox
|
||||
}
|
||||
|
||||
// NewBuffer creates a new buffer with the given configurations
|
||||
func NewBuffer(conf *cfg.TomlConfig, buffOpts BufferConfig, parent *View, index int) *Buffer {
|
||||
config := conf
|
||||
if config == nil {
|
||||
@ -249,6 +253,8 @@ func (b *Buffer) reload() {
|
||||
b.modified = false
|
||||
}
|
||||
|
||||
// OpenFile will open the given file path into this buffer.
|
||||
// This also handles loading of syntax stuff for syntax highlighting.
|
||||
func (b *Buffer) OpenFile(filePath string) {
|
||||
b.filePath = filePath
|
||||
|
||||
@ -506,8 +512,6 @@ func (b *Buffer) processTextInput(r rune) bool {
|
||||
if curr == r {
|
||||
b.moveRight()
|
||||
return true
|
||||
} else {
|
||||
log.Print("no it's ", curr)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1041,13 +1045,13 @@ func (b *Buffer) processActionKey(key int) bool {
|
||||
|
||||
// TODO remove since this is handled in the keymap!
|
||||
case strife.KEY_PAGEUP:
|
||||
b.scrollUp(DEFAULT_SCROLL_AMOUNT)
|
||||
for i := 0; i < DEFAULT_SCROLL_AMOUNT; i++ {
|
||||
b.scrollUp(DefaultScrollAmount)
|
||||
for i := 0; i < DefaultScrollAmount; i++ {
|
||||
b.moveUp()
|
||||
}
|
||||
case strife.KEY_PAGEDOWN:
|
||||
b.scrollDown(DEFAULT_SCROLL_AMOUNT)
|
||||
for i := 0; i < DEFAULT_SCROLL_AMOUNT; i++ {
|
||||
b.scrollDown(DefaultScrollAmount)
|
||||
for i := 0; i < DefaultScrollAmount; i++ {
|
||||
b.moveDown()
|
||||
}
|
||||
|
||||
@ -1109,10 +1113,10 @@ func (b *Buffer) HandleEvent(evt strife.StrifeEvent) {
|
||||
switch event := evt.(type) {
|
||||
case *strife.MouseWheelEvent:
|
||||
if event.Y > 0 {
|
||||
b.scrollDown(DEFAULT_SCROLL_AMOUNT)
|
||||
b.scrollDown(DefaultScrollAmount)
|
||||
}
|
||||
if event.Y < 0 {
|
||||
b.scrollUp(DEFAULT_SCROLL_AMOUNT)
|
||||
b.scrollUp(DefaultScrollAmount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
37
gui/view.go
37
gui/view.go
@ -17,16 +17,16 @@ type bufferEvent interface {
|
||||
String() string
|
||||
}
|
||||
|
||||
type ReloadBufferEvent struct {
|
||||
type reloadBufferEvent struct {
|
||||
buff *Buffer
|
||||
}
|
||||
|
||||
func (r *ReloadBufferEvent) Process(view *View) {
|
||||
func (r *reloadBufferEvent) Process(view *View) {
|
||||
log.Println("reloading buffer", r.buff.filePath)
|
||||
r.buff.reload()
|
||||
}
|
||||
|
||||
func (r *ReloadBufferEvent) String() string {
|
||||
func (r *reloadBufferEvent) String() string {
|
||||
return "reload-buffer-event"
|
||||
}
|
||||
|
||||
@ -44,6 +44,8 @@ type View struct {
|
||||
bufferEvents chan bufferEvent
|
||||
}
|
||||
|
||||
// NewView creaets a new view with the given width and height
|
||||
// as well as configurations.
|
||||
func NewView(width, height int, conf *cfg.TomlConfig) *View {
|
||||
view := &View{
|
||||
conf: conf,
|
||||
@ -58,6 +60,8 @@ func NewView(width, height int, conf *cfg.TomlConfig) *View {
|
||||
view.commandPalette = NewCommandPalette(*conf, view)
|
||||
view.UnfocusBuffers()
|
||||
|
||||
// TODO handle the fsnotify stuff properly.
|
||||
|
||||
var err error
|
||||
view.watcher, err = fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
@ -80,7 +84,7 @@ func NewView(width, height int, conf *cfg.TomlConfig) *View {
|
||||
break
|
||||
}
|
||||
|
||||
view.bufferEvents <- &ReloadBufferEvent{buff}
|
||||
view.bufferEvents <- &reloadBufferEvent{buff}
|
||||
log.Println("modified file:", event.Name)
|
||||
}
|
||||
case err := <-view.watcher.Errors:
|
||||
@ -112,6 +116,7 @@ func (n *View) registerFile(path string, buff *Buffer) {
|
||||
n.bufferMap[path] = buff
|
||||
}
|
||||
|
||||
// Close will close the view and all of the components
|
||||
func (n *View) Close() {
|
||||
n.watcher.Close()
|
||||
}
|
||||
@ -134,6 +139,8 @@ func (n *View) focusPalette(buff *Buffer) {
|
||||
p.parentBuff = buff
|
||||
}
|
||||
|
||||
// UnfocusBuffers will remove focus
|
||||
// from all of the buffers in this view.
|
||||
func (n *View) UnfocusBuffers() {
|
||||
// clear focus from buffers
|
||||
for _, buffPane := range n.buffers {
|
||||
@ -188,7 +195,14 @@ func (n *View) setFocusTo(index int) {
|
||||
buff.SetFocus(true)
|
||||
}
|
||||
|
||||
// FIXME
|
||||
// ChangeFocus will change the focus from the given
|
||||
// buffer in this view to another buffer. It takes a
|
||||
// `dir` (direction), e.g. -1, or 1 which tells what
|
||||
// way to change focus to. For example, -1, will change
|
||||
// focus to the left.
|
||||
//
|
||||
// NOTE: if we have no buffers to the left, we will
|
||||
// wrap around to the buffer on the far right.
|
||||
func (n *View) ChangeFocus(dir int) {
|
||||
// we cant change focus if there are no
|
||||
// buffers to focus to
|
||||
@ -233,9 +247,11 @@ func (n *View) getCurrentBuff() *Buffer {
|
||||
return nil
|
||||
}
|
||||
|
||||
// OnInit ...
|
||||
func (n *View) OnInit() {
|
||||
}
|
||||
|
||||
// OnUpdate ...
|
||||
func (n *View) OnUpdate() bool {
|
||||
dirty := false
|
||||
|
||||
@ -306,6 +322,12 @@ func (n *View) OnUpdate() bool {
|
||||
return dirty
|
||||
}
|
||||
|
||||
// Resize will resize all of the components in the view
|
||||
// The algorithm here used is basically to resize all of the
|
||||
// components so that they evenly fit into the view. This is
|
||||
// simply:
|
||||
//
|
||||
// viewWidth / bufferCount
|
||||
func (n *View) Resize(w, h int) {
|
||||
n.BaseComponent.Resize(w, h)
|
||||
|
||||
@ -329,6 +351,7 @@ func (n *View) Resize(w, h int) {
|
||||
}
|
||||
}
|
||||
|
||||
// OnRender ...
|
||||
func (n *View) OnRender(ctx *strife.Renderer) {
|
||||
for _, buffPane := range n.buffers {
|
||||
buffPane.OnRender(ctx)
|
||||
@ -345,8 +368,12 @@ func (n *View) OnRender(ctx *strife.Renderer) {
|
||||
}
|
||||
}
|
||||
|
||||
// OnDispose ...
|
||||
func (n *View) OnDispose() {}
|
||||
|
||||
// AddBuffer will unfocus all of the buffers
|
||||
// and insert a new buffer. Focus is given to this
|
||||
// new buffer, which is then returned from this function.
|
||||
func (n *View) AddBuffer() *Buffer {
|
||||
n.UnfocusBuffers()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user