Last active
June 6, 2022 00:29
-
-
Save nanjizal/e85865da7b19da080ae5d2516f82c322 to your computer and use it in GitHub Desktop.
Demo of 256 color in neko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# assumes putting classes in subdirectory 'src' | |
-cp src | |
--neko hello.n | |
--main Main | |
-cmd neko hello.n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SysPrint256; | |
class Main { | |
static final text = 'Hello'; | |
/** | |
* Demo of 256 color in terminal | |
**/ | |
static public function main():Void { | |
var cyan = 51; | |
var purple = 57; | |
var colortxt = fontColor( text, cyan, purple ); | |
Sys.println('$begin$colortxt$end'); | |
var str = ''; | |
for( i in 0...12 ){ | |
colortxt = fontColor( text, Std.random(256) ); | |
str += '$colortxt $begin'; | |
} | |
str = str.substr(0,str.length-begin.length); | |
println( str ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MIT license | |
// see pallette library | |
// https://github.com/nanjizal/pallette/blob/master/LICENSE | |
final begin = '\033['; | |
final end = '\033[0m'; | |
final fore = '38;5;'; | |
final back = '48;5;'; | |
function println( txt: String ){ | |
Sys.println('$begin$txt$end'); | |
} | |
function fontColor( txt: String, foreIndex: Int, ?backIndex: Int = -1 ){ | |
var foreColor = txColor( foreIndex ); | |
return if( backIndex == -1 ){ | |
'${foreColor}m$txt'; | |
} else { | |
var backColor = bgColor( backIndex ); | |
'$foreColor;${backColor}m$txt'; | |
} | |
} | |
function txColor( colorIndex: Int ){ | |
var color = Std.string( colorIndex ); | |
return '$fore$color'; | |
} | |
function bgColor( colorIndex: Int ){ | |
var color = Std.string( colorIndex ); | |
return '$back$color'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment