GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — cli/R/simple-theme.R at main · cderv/cli

Expand file tree

/

simple-theme.R

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
196 lines (174 loc) · 5.23 KB
/

simple-theme.R

Copy path

File metadata and controls

196 lines (174 loc) · 5.23 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#' A simple CLI theme
#'
#' Note that this is in addition to the builtin theme. To use this theme,
#' you can set it as the `cli.theme` option:
#'
#' ```
#' options(cli.theme = cli::simple_theme())
#' ```
#'
#' and then CLI apps started after this will use it as the default theme.
#' You can also use it temporarily, in a div element:
#'
#' ```
#' cli_div(theme = cli::simple_theme())
#' ```
#'
#' @param dark Whether the theme should be optiomized for a dark
#' background. If `"auto"`, then cli will try to detect this.
#' Detection usually works in recent RStudio versions, and in iTerm
#' on macOS, but not on other platforms.
#'
#' @seealso [themes], [builtin_theme()].
#' @export
#' @examples
#' cli_div(theme = cli::simple_theme())
#'
#' cli_h1("Heading 1")
#' cli_h2("Heading 2")
#' cli_h3("Heading 3")
#'
#' cli_alert_danger("Danger alert")
#' cli_alert_warning("Warning alert")
#' cli_alert_info("Info alert")
#' cli_alert_success("Success alert")
#' cli_alert("Alert for starting a process or computation",
#' class = "alert-start")
#'
#' cli_text("Packages and versions: {.pkg cli} {.version 1.0.0}.")
#' cli_text("Time intervals: {.timestamp 3.4s}")
#'
#' cli_text("{.emph Emphasis} and {.strong strong emphasis}")
#'
#' cli_text("This is a piece of code: {.code sum(x) / length(x)}")
#' cli_text("Function names: {.fn cli::simple_theme}")
#'
#' cli_text("Files: {.file /usr/bin/env}")
#' cli_text("URLs: {.url https://r-project.org}")
#'
#' cli_h2("Longer code chunk")
#' cli_par(class = "code R")
#' cli_verbatim(
#' '# window functions are useful for grouped mutates',
#' 'mtcars %>%',
#' ' group_by(cyl) %>%',
#' ' mutate(rank = min_rank(desc(mpg)))')
#' cli_end()
#'
#' cli_h2("Even longer code chunk")
#' cli_par(class = "code R")
#' cli_verbatim(format(ls))
#' cli_end()
#'
#' cli_end()
simple_theme <- function(dark = getOption("cli_theme_dark", "auto")) {
dark <- detect_dark_theme(dark)
list(
h1 = list(
"margin-top" = 1,
"margin-bottom" = 0,
color = "cyan",
fmt = function(x) cli::rule(x, line_col = "cyan")),
h2 = list(
"margin-top" = 1,
"margin-bottom" = 0,
color = "cyan",
fmt = function(x) paste0(symbol$line, " ", x, " ", symbol$line, symbol$line)),
h3 = list(
"margin-top" = 1,
"margin-bottom" = 0,
color = "cyan"),
par = list("margin-top" = 0, "margin-bottom" = 1),
".alert-danger" = list(
"background-color" = "red",
color = "white",
before = function() paste0(symbol$cross, " ")
),
".alert-warning" = list(
color = "orange",
"font-weight" = "bold",
before = paste0("!", " ")
),
".alert-success" = list(
before = function() paste0(col_green(symbol$tick), " ")
),
".alert-info" = list(
before = function() paste0(col_cyan(symbol$info), " ")
),
".alert-start" = list(
before = function() paste0(symbol$arrow_right, " ")),
span.pkg = list(
color = "blue",
"font-weight" = "bold"),
span.version = list(color = "blue"),
span.emph = simple_theme_emph(),
span.strong = list("font-weight" = "bold", "font-style" = "italic"),
span.fun = modifyList(simple_theme_code(dark), list(after = "()")),
span.fn = modifyList(simple_theme_code(dark), list(after = "()")),
span.arg = simple_theme_code(dark),
span.kbd = modifyList(simple_theme_code(dark),
list(before = "<", after = ">")),
span.key = modifyList(simple_theme_code(dark),
list(before = "<", after = ">")),
span.file = simple_theme_file(),
span.path = simple_theme_file(),
span.email = simple_theme_url(),
span.url = modifyList(simple_theme_url(),
list(before = "<", after = ">")),
span.var = simple_theme_code(dark),
span.envvar = simple_theme_code(dark),
span.timestamp = list(before = "[", after = "]", color = "grey")
)
}
simple_theme_emph <- function() {
list("font-style" = "italic")
}
simple_theme_url <- function() {
list(color = "blue")
}
simple_theme_code <- function(dark) {
if (dark) {
list("background-color" = "#232323", color = "#f0f0f0")
} else{
list("background-color" = "#f8f8f8", color = "#202020")
}
}
simple_theme_file <- function() {
list(color = "blue")
}
simple_theme_r_code <- function(dark) {
dark <- dark
style <- if (dark) {
make_ansi_style("#f0f0f0")
} else {
make_ansi_style("#202020")
}
function(x) {
x <- ansi_strip(x)
lines <- strsplit(x, "\n", fixed = TRUE)[[1]]
fmd <- tryCatch(prettycode::highlight(lines), error = function(x) lines)
style(fmd)
}
}
is_iterm <- function() {
isatty(stdout()) && Sys.getenv("TERM_PROGRAM", "") == "iTerm.app"
}
is_iterm_dark <- function() {
if (is.null(clienv[["is_iterm_dark"]])) {
clienv$is_iterm_dark <-
tryCatch(
error = function(x) FALSE, {
osa <- '
tell application "iTerm2"
tell current session of current window
get background color
end tell
end tell
'
out <- system2("osascript", c("-e", shQuote(osa)), stdout = TRUE)
nums <- scan(text = gsub(",", "", out), quiet = TRUE)
mean(nums) < 20000
})
}
clienv[["is_iterm_dark"]]
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.