main: Fix color schemes for abstract_ui

- Set 't_Co' to 256 at startup. The value can be changed by the user for
  compatibility with terminals that are less capable.
- `has('gui_running')` will return 1 if at least one rgb UI is attached.

Even though these changes are hacky, they are necessary to make the transition
to the new UI architecture smoother.
This commit is contained in:
Thiago de Arruda 2015-01-13 08:38:38 -03:00
parent 8f3e61a043
commit 3e9c55b51b
5 changed files with 24 additions and 13 deletions

View File

@ -76,6 +76,7 @@
#include "nvim/tag.h" #include "nvim/tag.h"
#include "nvim/tempfile.h" #include "nvim/tempfile.h"
#include "nvim/term.h" #include "nvim/term.h"
#include "nvim/ui.h"
#include "nvim/mouse.h" #include "nvim/mouse.h"
#include "nvim/undo.h" #include "nvim/undo.h"
#include "nvim/version.h" #include "nvim/version.h"
@ -10023,6 +10024,8 @@ static void f_has(typval_T *argvars, typval_T *rettv)
#endif #endif
} else if (STRICMP(name, "syntax_items") == 0) { } else if (STRICMP(name, "syntax_items") == 0) {
n = syntax_present(curwin); n = syntax_present(curwin);
} else if (STRICMP(name, "gui_running") == 0) {
n = ui_rgb_attached();
} }
} }
@ -14440,7 +14443,7 @@ static void f_synIDattr(typval_T *argvars, typval_T *rettv)
if (modec != 't' && modec != 'c' && modec != 'g') if (modec != 't' && modec != 'c' && modec != 'g')
modec = 0; /* replace invalid with current */ modec = 0; /* replace invalid with current */
} else { } else {
if (t_colors > 1) if (abstract_ui || t_colors > 1)
modec = 'c'; modec = 'c';
else else
modec = 't'; modec = 't';

View File

@ -261,10 +261,7 @@ int main(int argc, char **argv)
if (params.want_full_screen && !silent_mode) { if (params.want_full_screen && !silent_mode) {
if (embedded_mode) { if (embedded_mode) {
// In embedded mode don't do terminal-related initializations, assume an // embedded mode implies abstract_ui
// initial screen size of 80x20
full_screen = true;
screen_resize(80, 20, false);
termcapinit((uint8_t *)"abstract_ui"); termcapinit((uint8_t *)"abstract_ui");
} else { } else {
// set terminal name and get terminal capabilities (will set full_screen) // set terminal name and get terminal capabilities (will set full_screen)
@ -278,7 +275,9 @@ int main(int argc, char **argv)
event_init(); event_init();
if (abstract_ui) { if (abstract_ui) {
full_screen = true;
t_colors = 256; t_colors = 256;
T_CCO = (uint8_t *)"256";
} else { } else {
// Print a warning if stdout is not a terminal TODO(tarruda): Remove this // Print a warning if stdout is not a terminal TODO(tarruda): Remove this
// check once the new terminal UI is implemented // check once the new terminal UI is implemented

View File

@ -6150,8 +6150,7 @@ void screen_fill(int start_row, int end_row, int start_col, int end_col, int c1,
return; return;
/* it's a "normal" terminal when not in a GUI or cterm */ /* it's a "normal" terminal when not in a GUI or cterm */
norm_term = ( norm_term = (!abstract_ui && t_colors <= 1);
t_colors <= 1);
for (row = start_row; row < end_row; ++row) { for (row = start_row; row < end_row; ++row) {
if (has_mbyte if (has_mbyte
) { ) {
@ -6675,8 +6674,8 @@ static void linecopy(int to, int from, win_T *wp)
*/ */
int can_clear(char_u *p) int can_clear(char_u *p)
{ {
return *p != NUL && (t_colors <= 1 return abstract_ui || (*p != NUL && (t_colors <= 1
|| cterm_normal_bg_color == 0 || *T_UT != NUL); || cterm_normal_bg_color == 0 || *T_UT != NUL));
} }
/* /*

View File

@ -6450,7 +6450,7 @@ do_highlight (
p = T_CAF; p = T_CAF;
else else
p = T_CSF; p = T_CSF;
if (*p != NUL && *(p + STRLEN(p) - 1) == 'm') if (abstract_ui || (*p != NUL && *(p + STRLEN(p) - 1) == 'm'))
switch (t_colors) { switch (t_colors) {
case 16: case 16:
color = color_numbers_8[i]; color = color_numbers_8[i];
@ -6865,7 +6865,7 @@ int hl_combine_attr(int char_attr, int prim_attr)
if (char_attr <= HL_ALL && prim_attr <= HL_ALL) if (char_attr <= HL_ALL && prim_attr <= HL_ALL)
return char_attr | prim_attr; return char_attr | prim_attr;
if (t_colors > 1) { if (abstract_ui || t_colors > 1) {
if (char_attr > HL_ALL) if (char_attr > HL_ALL)
char_aep = syn_cterm_attr2entry(char_attr); char_aep = syn_cterm_attr2entry(char_attr);
if (char_aep != NULL) if (char_aep != NULL)
@ -6929,7 +6929,7 @@ int syn_attr2attr(int attr)
{ {
attrentry_T *aep; attrentry_T *aep;
if (t_colors > 1) if (abstract_ui || t_colors > 1)
aep = syn_cterm_attr2entry(attr); aep = syn_cterm_attr2entry(attr);
else else
aep = syn_term_attr2entry(attr); aep = syn_term_attr2entry(attr);
@ -7357,7 +7357,7 @@ int syn_id2attr(int hl_id)
hl_id = syn_get_final_id(hl_id); hl_id = syn_get_final_id(hl_id);
sgp = &HL_TABLE()[hl_id - 1]; /* index is ID minus one */ sgp = &HL_TABLE()[hl_id - 1]; /* index is ID minus one */
if (t_colors > 1) if (abstract_ui || t_colors > 1)
attr = sgp->sg_cterm_attr; attr = sgp->sg_cterm_attr;
else else
attr = sgp->sg_term_attr; attr = sgp->sg_term_attr;

View File

@ -114,6 +114,16 @@ void ui_write(uint8_t *s, int len)
free(tofree); free(tofree);
} }
bool ui_rgb_attached(void)
{
for (size_t i = 0; i < ui_count; i++) {
if (uis[i]->rgb) {
return true;
}
}
return false;
}
/* /*
* If the machine has job control, use it to suspend the program, * If the machine has job control, use it to suspend the program,
* otherwise fake it by starting a new shell. * otherwise fake it by starting a new shell.