public void ClearLineFromCursor() { int cx = Console.CursorLeft; int cy = Console.CursorTop; int w = Console.BufferWidth; // [ _ , _ , ... ,_ , X , X , ... , X ] // 0 cx w-1 // X's are unknown content to be overwritten, no of Xs = (w-1-cx+1) = cx - w , so yes always at least 1 ( cx <= w-1 ) string WS = SUH.NSpace(w - cx); Console.Write(WS); }
public void DisplayCurrentLine() { if (scroll && hist_len == 0) { throw new Exception("inv1 bug"); } Console.CursorVisible = false; int asking_y_start; if (Console.CursorTop >= last_render_Y_start && Console.CursorTop <= last_render_Y_end) // heueristic for overdrawing the last rendered line { asking_y_start = last_render_Y_start; // clear everything first - wasteful, but covers most edge cases for (int i = last_render_Y_start; i <= last_render_Y_end; i++) { Console.CursorTop = i; Console.CursorLeft = 0; Console.Write(SUH.NSpace(Console.BufferWidth)); } } else { // in case of not overdrawing, same heueristic as in TokenLine.RenderSelf : don't kill contents on the current line if (Console.CursorLeft == 0) { asking_y_start = Console.CursorTop; } else { asking_y_start = Console.CursorTop + 1; } } int y_start, y_end; currLine.RenderSelf(asking_y_start /* guesswork */, out y_start, out y_end); last_render_Y_start = y_start; last_render_Y_end = y_end; Console.CursorVisible = true; }
public bool col_itms_uptodate = true; // field initializers represent a valid empty tok_line - no sync needed public void toks2plain_string() { _plain_string = ""; foreach (var tok in _toks) { if (tok is PTokWhitespace) { _plain_string += SUH.NSpace((tok as PTokWhitespace).len); } else if (tok is PTok) { _plain_string += (tok as PTok).pay; } else if (tok == null) { _plain_string += ""; "warnig null in tokens".NLSend(); } // TODO : policy decision else { throw new NotImplementedException(); // and never will } } }
/* * since there are little dependencies on the precise structure of col_itm sequence, * atm the simplest possible implementation : * * every token gets exactly one col_itm * these could be compressed ( consequtive itms of same color into one ) - i do not yet know what makes the console window so riduculusly slow * - for lazyness sake old code fragment for the "not even partial parse possible"-case is still present -> everything compressed into a single col_itm */ public static IEnumerable <col_itm> GrammarColorize(IEnumerable <PTokBase> _lexxed) { PTokBase [] lexxed = _lexxed.ToArray(); PTok [] stripped = lexxed.Where(tok => tok is PTok).Select(tok => tok as PTok).ToArray(); NamedNode rootNode = null; try { rootNode = MG.RUN_with_rest(ColorizeStartProd, stripped).First().N; } catch (Exception) { } if (rootNode == null) { string err_str = ""; foreach (var tok in lexxed) // concatenate to a single error token -- maybe yield multiple ( for M-b,M-a style shortkeys ) ? { if (tok is PTokWhitespace) { err_str += SUH.NSpace((tok as PTokWhitespace).len); } if (tok is PTok) { err_str += (tok as PTok).pay; } } yield return(new col_itm { col = ConsoleColor.Red, str = err_str }); yield break; } // ------ MG.TermNode [] TNs = rootNode.Leafs().Where(nn => nn is MG.TermNode).Select(nn => (MG.TermNode)nn).ToArray(); // a NamedNode with STAR as topmost prod _CAN_ be a leaf ( TODO meditate on whether to allow such a construct in the final grammar ) int lexx_i = 0; int NN_i = 0; while (true) { if (lexx_i == lexxed.Length) { break; } PTokBase tok_base = lexxed[lexx_i]; if (tok_base is PTokWhitespace) { #region Whitespace-Block yield return(new col_itm { str = SUH.NSpace((tok_base as PTokWhitespace).len), col = defaultConsoleColor }); #endregion } else { if (NN_i == TNs.Length) { break; } #region Token-Block PTok tok = (PTok)tok_base; MG.TermNode TN = TNs[NN_i]; D.Assert(TN.tok == tok); // ---------- yield return(new col_itm { col = indicateCol(TN), str = tok.pay }); #endregion NN_i++; } lexx_i++; } for (; lexx_i < lexxed.Length; lexx_i++) { PTokBase tok = lexxed[lexx_i]; if (tok is PTokWhitespace) { yield return new col_itm { col = errorConsoleColor, str = SUH.NSpace((tok as PTokWhitespace).len) } } ; else { yield return new col_itm { col = errorConsoleColor, str = (tok as PTok).pay } }; } }