-
Notifications
You must be signed in to change notification settings - Fork 1
/
terminal.d
42 lines (39 loc) · 971 Bytes
/
terminal.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Written in the D programming language
// License: http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0
module util.terminal;
import util.io;
enum CSI = "\033[";
enum RESET=CSI~"0m";
enum BOLD=CSI~"1m";
enum BLACK =CSI~"30m";
enum RED =CSI~"31m";
enum GREEN=CSI~"32m";
enum YELLOW=CSI~"33m";
enum BLUE=CSI~"34m";
enum MAGENTA=CSI~"35m";
enum CYAN=CSI~"36m";
enum WHITE=CSI~"37m";
version(WASM){
bool isATTy(ref File){return false;}
int getTabSize(){
return 4;
}
}else version(linux){
import std.stdio;
import core.stdc.stdlib;
import core.stdc.string;
private extern(C) size_t isatty(size_t desc);
private extern(C) int fileno(shared(_iobuf)*);
bool isATTy(ref File f){ // determine whether a given file is connected to a terminal
if(!strcmp(getenv("TERM"),"dumb")) return false;
return cast(bool)isatty(fileno(f.getFP()));
}
int getTabSize(){
return 4;
}
}else{
bool isATTy(ref File){return false;}
int getTabSize(){
return 4;
}
}