mirror of
https://github.com/felixangell/phi.git
synced 2024-09-11 15:55:25 +03:00
dont seg fault when there is no highlighting info
This commit is contained in:
parent
1e6fc83b89
commit
264ec81fd6
@ -69,6 +69,7 @@ type RenderConfig struct {
|
||||
Accelerated bool
|
||||
Throttle_Cpu_Usage bool
|
||||
Always_Render bool
|
||||
Syntax_Highlighting bool
|
||||
}
|
||||
|
||||
// todo make this more extendable...
|
||||
|
@ -18,6 +18,7 @@ aliased = true
|
||||
accelerated = true
|
||||
throttle_cpu_usage = true
|
||||
always_render = true
|
||||
syntax_highlighting = true
|
||||
|
||||
[file_associations]
|
||||
[file_associations.c]
|
||||
|
@ -18,6 +18,7 @@ aliased = true
|
||||
accelerated = true
|
||||
throttle_cpu_usage = true
|
||||
always_render = true
|
||||
syntax_highlighting = true
|
||||
|
||||
[file_associations]
|
||||
[file_associations.c]
|
||||
|
@ -18,6 +18,7 @@ aliased = true
|
||||
accelerated = true
|
||||
throttle_cpu_usage = true
|
||||
always_render = true
|
||||
syntax_highlighting = true
|
||||
|
||||
[file_associations]
|
||||
[file_associations.c]
|
||||
|
105
gui/buffer.go
105
gui/buffer.go
@ -755,54 +755,7 @@ var ex, ey = 0, 0
|
||||
|
||||
var compiledRegex = map[string]*regexp.Regexp{}
|
||||
|
||||
func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
|
||||
// BACKGROUND
|
||||
ctx.SetColor(strife.HexRGB(b.cfg.Theme.Background))
|
||||
ctx.Rect(b.x, b.y, b.w, b.h, strife.Fill)
|
||||
|
||||
if b.cfg.Editor.Highlight_Line && b.HasFocus {
|
||||
ctx.SetColor(strife.Black) // highlight_line_col?
|
||||
ctx.Rect(ex+rx, ey+(ry+b.curs.ry*last_h)-(b.cam.y*last_h), b.w, last_h, strife.Fill)
|
||||
}
|
||||
|
||||
// render the ol' cursor
|
||||
if b.HasFocus && renderFlashingCursor && b.cfg.Cursor.Draw {
|
||||
cursorWidth := b.cfg.Cursor.GetCaretWidth()
|
||||
if cursorWidth == -1 {
|
||||
cursorWidth = last_w
|
||||
}
|
||||
|
||||
ctx.SetColor(strife.HexRGB(b.cfg.Theme.Cursor)) // caret colour
|
||||
ctx.Rect(ex+(rx+b.curs.rx*last_w)-(b.cam.x*last_w), (ry+b.curs.ry*last_h)-(b.cam.y*last_h), cursorWidth, last_h, strife.Fill)
|
||||
}
|
||||
|
||||
var visibleLines int = 50
|
||||
|
||||
// last_h > 0 means we have done
|
||||
// a render.
|
||||
if int(last_h) > 0 && int(b.h) != 0 {
|
||||
// render an extra three lines just
|
||||
// so we dont cut anything off if its
|
||||
// not evenly divisible
|
||||
visibleLines = (int(b.h) / int(last_h)) + 3
|
||||
}
|
||||
|
||||
start := b.cam.y
|
||||
upper := b.cam.y + visibleLines
|
||||
if start > len(b.contents) {
|
||||
start = len(b.contents)
|
||||
}
|
||||
if upper > len(b.contents) {
|
||||
upper = len(b.contents)
|
||||
}
|
||||
|
||||
numLines := len(b.contents)
|
||||
|
||||
var y_col int
|
||||
for lineNum, rope := range b.contents[start:upper] {
|
||||
currLine := []rune(rope.String())
|
||||
|
||||
// char index => colour
|
||||
func (b *Buffer) syntaxHighlightLine(currLine string) map[int]syntaxRuneInfo {
|
||||
matches := map[int]syntaxRuneInfo{}
|
||||
|
||||
subjects := make([]cfg.SyntaxCriteria, len(b.languageInfo.Syntax))
|
||||
@ -871,6 +824,62 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
|
||||
}
|
||||
}
|
||||
|
||||
return matches
|
||||
}
|
||||
|
||||
func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
|
||||
// BACKGROUND
|
||||
ctx.SetColor(strife.HexRGB(b.cfg.Theme.Background))
|
||||
ctx.Rect(b.x, b.y, b.w, b.h, strife.Fill)
|
||||
|
||||
if b.cfg.Editor.Highlight_Line && b.HasFocus {
|
||||
ctx.SetColor(strife.Black) // highlight_line_col?
|
||||
ctx.Rect(ex+rx, ey+(ry+b.curs.ry*last_h)-(b.cam.y*last_h), b.w, last_h, strife.Fill)
|
||||
}
|
||||
|
||||
// render the ol' cursor
|
||||
if b.HasFocus && renderFlashingCursor && b.cfg.Cursor.Draw {
|
||||
cursorWidth := b.cfg.Cursor.GetCaretWidth()
|
||||
if cursorWidth == -1 {
|
||||
cursorWidth = last_w
|
||||
}
|
||||
|
||||
ctx.SetColor(strife.HexRGB(b.cfg.Theme.Cursor)) // caret colour
|
||||
ctx.Rect(ex+(rx+b.curs.rx*last_w)-(b.cam.x*last_w), (ry+b.curs.ry*last_h)-(b.cam.y*last_h), cursorWidth, last_h, strife.Fill)
|
||||
}
|
||||
|
||||
var visibleLines int = 50
|
||||
|
||||
// last_h > 0 means we have done
|
||||
// a render.
|
||||
if int(last_h) > 0 && int(b.h) != 0 {
|
||||
// render an extra three lines just
|
||||
// so we dont cut anything off if its
|
||||
// not evenly divisible
|
||||
visibleLines = (int(b.h) / int(last_h)) + 3
|
||||
}
|
||||
|
||||
start := b.cam.y
|
||||
upper := b.cam.y + visibleLines
|
||||
if start > len(b.contents) {
|
||||
start = len(b.contents)
|
||||
}
|
||||
if upper > len(b.contents) {
|
||||
upper = len(b.contents)
|
||||
}
|
||||
|
||||
numLines := len(b.contents)
|
||||
|
||||
var y_col int
|
||||
for lineNum, rope := range b.contents[start:upper] {
|
||||
currLine := []rune(rope.String())
|
||||
|
||||
// char index => colour
|
||||
var matches map[int]syntaxRuneInfo
|
||||
if b.languageInfo != nil {
|
||||
matches = b.syntaxHighlightLine(string(currLine))
|
||||
}
|
||||
|
||||
colorStack := []int{}
|
||||
|
||||
var x_col int
|
||||
|
Loading…
Reference in New Issue
Block a user