public bool JoinChunk(Chunk nextChunk, int leftMargin) { int newWidth = MeasureWidth(text + nextChunk.text); if (!absNewline && leftMargin + newWidth <= ConsoleWidth && brush.Color == nextChunk.brush.Color && strikeout == nextChunk.strikeout) { text += nextChunk.text; bounds.Width = newWidth; newline = nextChunk.newline; absNewline = nextChunk.absNewline; return true; } else return false; }
void updateImage(Chunk chunk) { //one or more image chunks have finished downloading images //update only if not printing (otherwise update will be called as usual) if (!timerPrint.Enabled) { if (timerPrint.Interval == ZERO_DELAY || chunk.IsImgExpanding()) jumpToLastLine(); //also force drawing this.Invalidate(); } }
void checkIfBully(Chunk chunk, int x) { //check if image chunk grew so big it pushed the next chunk out of console window bounds int ind = getChunkIndex(chunk); if (ind != -1 && ind < chunks.Count - 1) { if (x + chunks[ind + 1].GetWidth() > this.Width) { //send the next chunk to a new line chunk.InsertNewline(); //jumpToLastLine(); //this.OnResize(new EventArgs()); } } }
void sendChunkToNewLine(Chunk chunk) { //make previous chunk have newline int ind = getChunkIndex(chunk); if (ind > 0) chunks[ind - 1].InsertNewline(); }
void print(string txt, string link, bool newline, Color color, bool strikeout) { if (txt == "") txt = " "; //blank line if (lastChunk == -1) lastChunk = 0; while (txt.Contains("<image=")) { //split into chunks int lb = txt.IndexOf("<image="); if (lb != 0) print(txt.Substring(0, lb), link, false, color, strikeout); //print text before image lb += 7; int ub = txt.IndexOf('>', lb); if (ub != -1) { //print img string imgLocation = txt.Substring(lb, ub - lb); if (link == "") { link = imgLocation; if (link.Contains("pbs.twimg.com")) link += ":large"; //open large versions of Twitter images } Chunk imgChunk = new Chunk(imgLocation, link, newline && ub == txt.Length - 1, newline); //can img fit in current line? if (leftMargin + imgChunk.GetWidth(true) > this.Width && chunks.Count > 0) chunks[chunks.Count - 1].InsertNewline(); //nope, send img to next line chunks.Add(imgChunk); if (newline && ub == txt.Length - 1) leftMargin = 0; else leftMargin += imgChunk.GetWidth(true); showNewChunks(); txt = txt.Substring(ub + 1); if (txt == "") return; } else break; } if (timerPrint.Interval == ZERO_DELAY) txt = txt.Replace("<pause>", ""); else txt = txt.Replace("<pause>", Environment.NewLine + "<pause>" + Environment.NewLine); string[] lines = txt.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < lines.Length; i++) { bool nLine = i == lines.Length - 1 ? newline : true; List<Chunk> newChunks = Chunk.Chunkify(lines[i], link, color, strikeout, leftMargin, nLine, nLine); chunks.AddRange(newChunks); if (nLine) leftMargin = 0; else { if (newChunks.Count > 1) leftMargin = 0; leftMargin += newChunks[newChunks.Count - 1].GetWidth(); } } showNewChunks(); }
int getChunkIndex(Chunk chunk) { int ind = 0; while (ind < chunks.Count) { if (chunks[ind] == chunk) return ind; ind++; } return -1; }