patch 8.0.1783: cannot use 256 colors in a MS-Windows console

Problem:    Cannot use 256 colors in a MS-Windows console.
Solution:   Add 256 color support. (Nobuhiro Takasaki, closes #2821)
diff --git a/src/option.c b/src/option.c
index 807b1e0..b4a0e6b 100644
--- a/src/option.c
+++ b/src/option.c
@@ -6082,6 +6082,9 @@
     int		redraw_gui_only = FALSE;
 #endif
     int		ft_changed = FALSE;
+#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
+    int		did_swaptcap = FALSE;
+#endif
 
     /* Get the global option to compare with, otherwise we would have to check
      * two values for all local options. */
@@ -6821,6 +6824,13 @@
 			vim_free(T_CCO);
 		    T_CCO = empty_option;
 		}
+#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
+		if (is_term_win32())
+		{
+		    swap_tcap();
+		    did_swaptcap = TRUE;
+		}
+#endif
 		/* We now have a different color setup, initialize it again. */
 		init_highlight(TRUE, FALSE);
 	    }
@@ -7674,6 +7684,16 @@
 #endif
 	check_redraw(options[opt_idx].flags);
 
+#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
+    if (did_swaptcap)
+    {
+	if (t_colors < 256)
+	    p_tgc = 0;
+	set_termname((char_u *)"win32");
+	init_highlight(TRUE, FALSE);
+    }
+#endif
+
     return errmsg;
 }
 
@@ -8716,7 +8736,8 @@
 	    p_tgc = 0;
 	    return (char_u*)N_("E954: 24-bit colors are not supported on this environment");
 	}
-	swap_tcap();
+	if (is_term_win32())
+	    swap_tcap();
 # endif
 # ifdef FEAT_GUI
 	if (!gui.in_use && !gui.starting)
@@ -8725,7 +8746,7 @@
 # ifdef FEAT_VTP
 	control_console_color_rgb();
 	/* reset t_Co */
-	if (STRCMP(T_NAME, "win32") == 0)
+	if (is_term_win32())
 	    set_termname(T_NAME);
 # endif
     }