public static JsonPalette Auto(ConsoleBrush defaultBrush) { string setting; try { setting = Settings.Default[defaultBrush.Background + "Palette"]; } catch (KeyNotFoundException) { setting = null; } if (string.IsNullOrEmpty(setting)) { setting = Settings.BlackPalette; defaultBrush = new ConsoleBrush(ConsoleColor.White, ConsoleColor.Black); } var palette = new JsonPalette(defaultBrush); palette.ImportJson(setting); return(palette); }
public JsonPalette(ConsoleBrush defaultBrush) { DefaultBrush = defaultBrush; Null = defaultBrush; String = defaultBrush; Number = defaultBrush; Boolean = defaultBrush; Object = defaultBrush; Member = defaultBrush; Array = defaultBrush; }
public JsonPalette(ConsoleBrush defaultBrush) { this.defaultBrush = defaultBrush; this.nullBrush = defaultBrush; this.stringBrush = defaultBrush; this.numberBrush = defaultBrush; this.booleanBrush = defaultBrush; this.objectBrush = defaultBrush; this.memberBrush = defaultBrush; this.arrayBrush = defaultBrush; }
public static JsonPalette Auto(ConsoleBrush defaultBrush) { string setting; try { setting = (string) Settings.Default[defaultBrush.Background + "Palette"]; } catch (SettingsPropertyNotFoundException) { setting = null; } if (string.IsNullOrEmpty(setting)) { setting = Settings.Default.BlackPalette; defaultBrush = new ConsoleBrush(ConsoleColor.White, ConsoleColor.Black); } var palette = new JsonPalette(defaultBrush); palette.ImportJson(setting); return palette; }
void IJsonImportable.Import(ImportContext context, JsonReader reader) { reader.MoveToContent(); if (reader.TokenClass != JsonTokenClass.Object) { reader.Skip(); return; } reader.Read(/* object */); do { var brushName = reader.ReadMember().ToLowerInvariant(); var color = reader.ReadString(); var foreground = EnumHelper.TryParse<ConsoleColor>(color, true) ?? DefaultBrush.Foreground; switch (brushName) { case "arr": case "array": Array = Array.ResetForeground(foreground); break; case "obj": case "object": Object = Object.ResetForeground(foreground); break; case "mem": case "member": Member = Member.ResetForeground(foreground); break; case "str": case "string": String = String.ResetForeground(foreground); break; case "num": case "number": Number = Number.ResetForeground(foreground); break; case "bit": case "boolean": Boolean = Boolean.ResetForeground(foreground); break; case "nil": case "null": Null = Null.ResetForeground(foreground); break; default: continue; } } while (reader.TokenClass != JsonTokenClass.EndObject); reader.Read( /* end object */); }
void IJsonImportable.Import(ImportContext context, JsonReader reader) { reader.MoveToContent(); if (reader.TokenClass != JsonTokenClass.Object) { reader.Skip(); return; } reader.Read(/* object */); do { var brushName = reader.ReadMember().ToLowerInvariant(); var color = reader.ReadString(); var foreground = Enum.TryParse <ConsoleColor>(color, true, out var cc) ? cc : DefaultBrush.Foreground; switch (brushName) { case "arr": case "array": Array = Array.ResetForeground(foreground); break; case "obj": case "object": Object = Object.ResetForeground(foreground); break; case "mem": case "member": Member = Member.ResetForeground(foreground); break; case "str": case "string": String = String.ResetForeground(foreground); break; case "num": case "number": Number = Number.ResetForeground(foreground); break; case "bit": case "boolean": Boolean = Boolean.ResetForeground(foreground); break; case "nil": case "null": Null = Null.ResetForeground(foreground); break; default: continue; } }while (reader.TokenClass != JsonTokenClass.EndObject); reader.Read(/* end object */); }