Goland編輯器設置選擇范圍背景色的操作
為了區(qū)分選擇與未選擇區(qū)域,,將已選擇區(qū)域的文本背景色設置為淺藍色是個很做法。
設置的路徑在 Editor > Color Scheme > General > Editor > Selection background 下面以2018版的Goland為例,如圖:

JetBrains出品的如phpStorm和webStorm等的設置也基本如此。
補充:Go語言:控制臺輸出有顏色的字
本方法只限用于 Windows系統(tǒng)
應用場景
需要輸出大量信息的運行日志(一般是服務器,Windows系統(tǒng)的)
某類客戶端的調(diào)試界面(一般是游戲,特別是有第三方模組的)
代碼示例
package main
import (
"syscall"
)
var (
kernel32 *syscall.LazyDLL = syscall.NewLazyDLL(`kernel32.dll`)
proc *syscall.LazyProc = kernel32.NewProc(`SetConsoleTextAttribute`)
CloseHandle *syscall.LazyProc = kernel32.NewProc(`CloseHandle`)
// 給字體顏色對象賦值
FontColor Color = Color{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
)
type Color struct {
black int // 黑色
blue int // 藍色
green int // 綠色
cyan int // 青色
red int // 紅色
purple int // 紫色
yellow int // 黃色
light_gray int // 淡灰色(系統(tǒng)默認值)
gray int // 灰色
light_blue int // 亮藍色
light_green int // 亮綠色
light_cyan int // 亮青色
light_red int // 亮紅色
light_purple int // 亮紫色
light_yellow int // 亮黃色
white int // 白色
}
// 輸出有顏色的字體
func ColorPrint(s string, i int) {
handle, _, _ := proc.Call(uintptr(syscall.Stdout), uintptr(i))
print(s)
CloseHandle.Call(handle)
}
func main() {
ColorPrint(`紅色`, FontColor.red)
ColorPrint(`藍色`, FontColor.blue)
ColorPrint(`白色`, FontColor.white)
}
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。
相關文章
Go語言中的goroutine和channel如何協(xié)同工作
在Go語言中,goroutine和channel是并發(fā)編程的兩個核心概念,它們協(xié)同工作以實現(xiàn)高效、安全的并發(fā)執(zhí)行,本文將詳細探討goroutine和channel如何協(xié)同工作,以及它們在并發(fā)編程中的作用和優(yōu)勢,需要的朋友可以參考下2024-04-04

