mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-05 14:40:20 +09:00
Add some comments
This commit is contained in:
@@ -63,6 +63,13 @@ var (
|
||||
BTRaw = BufType{4, true, true}
|
||||
)
|
||||
|
||||
// Buffer stores the main information about a currently open file including
|
||||
// the actual text (in a LineArray), the undo/redo stack (in an EventHandler)
|
||||
// all the cursors, the syntax highlighting info, the settings for the buffer
|
||||
// and some misc info about modification time and path location.
|
||||
// The syntax highlighting info must be stored with the buffer because the syntax
|
||||
// highlighter attaches information to each line of the buffer for optimization
|
||||
// purposes so it doesn't have to rehighlight everything on every update.
|
||||
type Buffer struct {
|
||||
*LineArray
|
||||
*EventHandler
|
||||
@@ -224,26 +231,32 @@ func (b *Buffer) ReOpen() error {
|
||||
// b.Cursor.Relocate()
|
||||
}
|
||||
|
||||
// SetCursors resets this buffer's cursors to a new list
|
||||
func (b *Buffer) SetCursors(c []*Cursor) {
|
||||
b.cursors = c
|
||||
}
|
||||
|
||||
// GetActiveCursor returns the main cursor in this buffer
|
||||
func (b *Buffer) GetActiveCursor() *Cursor {
|
||||
return b.cursors[0]
|
||||
}
|
||||
|
||||
// GetCursor returns the nth cursor
|
||||
func (b *Buffer) GetCursor(n int) *Cursor {
|
||||
return b.cursors[n]
|
||||
}
|
||||
|
||||
// GetCursors returns the list of cursors in this buffer
|
||||
func (b *Buffer) GetCursors() []*Cursor {
|
||||
return b.cursors
|
||||
}
|
||||
|
||||
// NumCursors returns the number of cursors
|
||||
func (b *Buffer) NumCursors() int {
|
||||
return len(b.cursors)
|
||||
}
|
||||
|
||||
// LineBytes returns line n as an array of bytes
|
||||
func (b *Buffer) LineBytes(n int) []byte {
|
||||
if n >= len(b.lines) || n < 0 {
|
||||
return []byte{}
|
||||
@@ -251,10 +264,12 @@ func (b *Buffer) LineBytes(n int) []byte {
|
||||
return b.lines[n].data
|
||||
}
|
||||
|
||||
// LinesNum returns the number of lines in the buffer
|
||||
func (b *Buffer) LinesNum() int {
|
||||
return len(b.lines)
|
||||
}
|
||||
|
||||
// Start returns the start of the buffer
|
||||
func (b *Buffer) Start() Loc {
|
||||
return Loc{0, 0}
|
||||
}
|
||||
@@ -392,6 +407,8 @@ func (b *Buffer) UpdateRules() {
|
||||
}
|
||||
}
|
||||
|
||||
// IndentString returns this buffer's indent method (a tabstop or n spaces
|
||||
// depending on the settings)
|
||||
func (b *Buffer) IndentString(tabsize int) string {
|
||||
if b.Settings["tabstospaces"].(bool) {
|
||||
return Spaces(tabsize)
|
||||
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
"github.com/zyedidia/tcell"
|
||||
)
|
||||
|
||||
// The InfoBar displays messages and other info at the bottom of the screen.
|
||||
// It is respresented as a buffer and a message with a style.
|
||||
type InfoBar struct {
|
||||
*buffer.Buffer
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ type Window interface {
|
||||
Clear()
|
||||
}
|
||||
|
||||
// The BufWindow provides a way of displaying a certain section
|
||||
// of a buffer
|
||||
type BufWindow struct {
|
||||
// X and Y coordinates for the top left of the window
|
||||
X int
|
||||
@@ -37,6 +39,7 @@ type BufWindow struct {
|
||||
sline *StatusLine
|
||||
}
|
||||
|
||||
// NewBufWindow creates a new window at a location in the screen with a width and height
|
||||
func NewBufWindow(x, y, width, height int, buf *buffer.Buffer) *BufWindow {
|
||||
w := new(BufWindow)
|
||||
w.X, w.Y, w.Width, w.Height, w.Buf = x, y, width, height, buf
|
||||
@@ -46,6 +49,7 @@ func NewBufWindow(x, y, width, height int, buf *buffer.Buffer) *BufWindow {
|
||||
return w
|
||||
}
|
||||
|
||||
// Clear resets all cells in this window to the default style
|
||||
func (w *BufWindow) Clear() {
|
||||
for y := 0; y < w.Height; y++ {
|
||||
for x := 0; x < w.Width; x++ {
|
||||
@@ -132,10 +136,10 @@ func (w *BufWindow) displayBuffer() {
|
||||
|
||||
// this represents the current draw position
|
||||
// within the current window
|
||||
vloc := buffer.Loc{0, 0}
|
||||
vloc := buffer.Loc{X: 0, Y: 0}
|
||||
|
||||
// this represents the current draw position in the buffer (char positions)
|
||||
bloc := buffer.Loc{w.StartCol, w.StartLine}
|
||||
bloc := buffer.Loc{X: w.StartCol, Y: w.StartLine}
|
||||
|
||||
activeC := w.Buf.GetActiveCursor()
|
||||
|
||||
@@ -233,6 +237,7 @@ func (w *BufWindow) displayStatusLine() {
|
||||
w.sline.Display()
|
||||
}
|
||||
|
||||
// Display displays the buffer and the statusline
|
||||
func (w *BufWindow) Display() {
|
||||
w.displayBuffer()
|
||||
w.displayStatusLine()
|
||||
|
||||
@@ -10,6 +10,12 @@ import (
|
||||
"github.com/zyedidia/tcell"
|
||||
)
|
||||
|
||||
// Screen is the tcell screen we use to draw to the terminal
|
||||
// Synchronization is used because we poll the screen on a separate
|
||||
// thread and sometimes the screen is shut down by the main thread
|
||||
// (for example on TermMessage) so we don't want to poll a nil/shutdown
|
||||
// screen. TODO: maybe we should worry about polling and drawing at the
|
||||
// same time too.
|
||||
var Screen tcell.Screen
|
||||
var lock sync.Mutex
|
||||
|
||||
@@ -23,6 +29,7 @@ func Unlock() {
|
||||
|
||||
var screenWasNil bool
|
||||
|
||||
// TempFini shuts the screen down temporarily
|
||||
func TempFini() {
|
||||
screenWasNil = Screen == nil
|
||||
|
||||
@@ -33,6 +40,7 @@ func TempFini() {
|
||||
}
|
||||
}
|
||||
|
||||
// TempStart restarts the screen after it was temporarily disabled
|
||||
func TempStart() {
|
||||
if !screenWasNil {
|
||||
Init()
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
)
|
||||
|
||||
// GetMemStats returns a string describing the memory usage and gc time used so far
|
||||
func GetMemStats() string {
|
||||
var memstats runtime.MemStats
|
||||
runtime.ReadMemStats(&memstats)
|
||||
|
||||
Reference in New Issue
Block a user