Implement syntax highlighting

This commit is contained in:
Kovid Goyal
2023-03-21 16:43:23 +05:30
parent 4d61ad87b3
commit c2e549b79c
8 changed files with 280 additions and 18 deletions

View File

@@ -22,6 +22,20 @@ func NewLRUCache[K comparable, V any](max_size int) *LRUCache[K, V] {
return &ans
}
func (self *LRUCache[K, V]) Get(key K) (ans V, found bool) {
self.lock.RLock()
ans, found = self.data[key]
self.lock.RUnlock()
return
}
func (self *LRUCache[K, V]) Set(key K, val V) {
self.lock.RLock()
self.data[key] = val
self.lock.RUnlock()
return
}
func (self *LRUCache[K, V]) GetOrCreate(key K, create func(key K) (V, error)) (V, error) {
self.lock.RLock()
ans, found := self.data[key]

View File

@@ -82,6 +82,10 @@ func (self *RGBA) AsRGB() uint32 {
return uint32(self.Blue) | (uint32(self.Green) << 8) | (uint32(self.Red) << 16)
}
func (self *RGBA) IsDark() bool {
return self.Red < 155 && self.Green < 155 && self.Blue < 155
}
func (self *RGBA) FromRGB(col uint32) {
self.Red = uint8((col >> 16) & 0xff)
self.Green = uint8((col >> 8) & 0xff)