private static int Example1() { Console.Clear(); var width = 80; var height = 25; Console.SetWindowSize(width, height); Console.SetBufferSize(width, height); Console.SetWindowSize(width, height); var cx = Console.WindowWidth; var cy = Console.WindowHeight; for (var y = 0; y < cy; y++) { for (var x = 0; x < cx; x++) { var r = (int)((float)x / cx * 255); var g = (int)((float)y / cy * 255); var b = (int)(1.0f * 255); var value = $"{(y * cx + x) % 10}"; VTConsole.Write(value, Color.Black, Color.FromArgb(r, g, b)); } } return(cy); }
private static void Example2() { Console.Clear(); for (var i = 0; i < Console.WindowHeight / 4; i++) { Sleep(50); VTConsole.ScrollUp(); } VTConsole.WriteLine("Disabling cursor blinking", Color.White, Color.Red); VTConsole.CursorSetBlinking(false); Sleep(); VTConsole.WriteLine("Enabling cursor blinking", Color.White, Color.Green); VTConsole.CursorSetBlinking(true); Sleep(); VTConsole.SetColorBackground(Color.White); VTConsole.WriteLine("Hiding cursor", Color.DeepPink); VTConsole.CursorSetVisibility(false); Sleep(); VTConsole.WriteLine("Showing cursor", Color.DeepSkyBlue); VTConsole.CursorSetVisibility(true); Sleep(); VTConsole.WriteLine(); VTConsole.SetFormat(VTFormat.Underline, VTFormat.Negative); VTConsole.WriteLine("Press a key to exit !!!", Color.White, Color.Red); }
private void WriteHeader() { VTConsole.SetColorBackground(Color.Black); VTConsole.EraseInDisplay(VTEraseMode.Entirely); VTConsole.WriteConcat("\x1b", "[1m"); VTConsole.WriteLine($"Yate Status Monitor {Version} - (c) zivillian <*****@*****.**>", Color.Yellow, Color.Blue); VTConsole.EraseInLine(); VTConsole.Write("\x1b[22m", Color.White, Color.Black); }
private static void Main(string[] args) { if (!VTConsole.IsSupported) { throw new NotSupportedException(); } VTConsole.Enable(); Example3(); Console.ReadKey(); }
public static void WriteHeader() { if (VTConsole.IsSupported) { VTConsole.Enable(); } using var fontStream = typeof(Consts).Assembly.GetManifestResourceStream( $"{typeof(Consts).Assembly.GetName().Name}.Fonts.big.flf" ); var font = FigletFont.Load(fontStream); var figlet = new Figlet(font); void WriteSegments((string str, Color color)[] columns)
protected override Task <int> ExecuteCommand(AboutCommand arguments) { if (VTConsole.IsSupported && !VTConsole.IsEnabled) { VTConsole.Enable(); } var assembly = typeof(AboutCommandHandler).Assembly; using var pngStream = assembly.GetManifestResourceStream( $"{typeof(AboutCommandHandler).Assembly.GetName().Name}.Images.icon-64x64.png" ); VTConsole.SetConsoleWidth80(); using var bitmap = SKBitmap.Decode(pngStream); var builder = new StringBuilder(bitmap.Width * bitmap.Height * 22); for (var j = 0; j < bitmap.Height; j = j + 2) { for (var i = 0; i < bitmap.Width; i++) { var pixel = bitmap.GetPixel(i, j); var str = VTConsole.GetColorBackgroundString(pixel.Red, pixel.Green, pixel.Blue); builder.Append(str); builder.Append(' '); } var backStr = VTConsole.GetColorBackgroundString(0, 0, 0); builder.AppendLine(backStr); } var bytes = Encoding.ASCII.GetBytes(builder.ToString()); VTConsole.WriteFast(bytes); if (VTConsole.IsSupported && VTConsole.IsEnabled) { VTConsole.Disable(); } return(Task.FromResult(0)); }
public static void ConsoleWriteImage2(Bitmap bmpSrc) { int sMax = size; decimal percent = Math.Min(decimal.Divide(sMax, bmpSrc.Width), decimal.Divide(sMax, bmpSrc.Height)); Size resSize = new Size((int)(bmpSrc.Width * percent), (int)(bmpSrc.Height * percent)); /*Func<System.Drawing.Color, int> ToConsoleColor = c => * { * int index = (c.R > 128 | c.G > 128 | c.B > 128) ? 8 : 0; * index |= (c.R > 64) ? 4 : 0; * index |= (c.G > 64) ? 2 : 0; * index |= (c.B > 64) ? 1 : 0; * return index; * };*/ Bitmap bmpMin = new Bitmap(bmpSrc, resSize.Width, resSize.Height); Bitmap bmpMax = new Bitmap(bmpSrc, resSize.Width * 2, resSize.Height * 2); var builder = new StringBuilder((resSize.Width + 1) * resSize.Height); for (int i = 0; i < resSize.Height; i++) { string str = ""; for (int j = 0; j < resSize.Width; j++) { str += VTConsole.GetColorForegroundString(bmpMax.GetPixel(j * 2, i * 2).R, bmpMax.GetPixel(j * 2, i * 2).G, bmpMax.GetPixel(j * 2, i * 2).B); str += VTConsole.GetColorBackgroundString(bmpMax.GetPixel(j * 2, i * 2 + 1).R, bmpMax.GetPixel(j * 2, i * 2 + 1).G, bmpMax.GetPixel(j * 2, i * 2 + 1).B); str += "▀"; str += VTConsole.GetColorForegroundString(bmpMax.GetPixel(j * 2 + 1, i * 2).R, bmpMax.GetPixel(j * 2 + 1, i * 2).G, bmpMax.GetPixel(j * 2 + 1, i * 2).B); str += VTConsole.GetColorBackgroundString(bmpMax.GetPixel(j * 2 + 1, i * 2 + 1).R, bmpMax.GetPixel(j * 2 + 1, i * 2 + 1).G, bmpMax.GetPixel(j * 2 + 1, i * 2 + 1).B); str += "▀"; } str += Environment.NewLine; builder.Append(str); } var bytes = Encoding.UTF8.GetBytes(builder.ToString()); VTConsole.WriteFast(bytes); }
private static void Example3() { var plasma = new Plasma(256, 256); var width = 80; var height = 40; Console.SetWindowSize(width, height); Console.SetBufferSize(width, height); Console.SetWindowSize(width, height); // removes bars Console.Title = "Plasma !"; Console.CursorVisible = false; var builder = new StringBuilder(width * height * 22); for (var frame = 0; ; frame++) { plasma.PlasmaFrame(frame); builder.Clear(); Thread.Sleep((int)(1.0 / 20 * 1000)); for (var i = 0; i < width * height; i++) { var x1 = i % width; var y1 = i / width; var i1 = y1 * plasma.SizeX + x1; var b = plasma.Screen[i1]; var cr = plasma.ColR[b] >> 4; var cg = plasma.ColG[b] >> 4; var cb = plasma.ColB[b] >> 4; var str = VTConsole.GetColorBackgroundString(cr, cg, cb); builder.Append(str); builder.Append(' '); } var bytes = Encoding.ASCII.GetBytes(builder.ToString()); VTConsole.WriteFast(bytes); } }
private void Execute() { VTConsole.Enable(); VTConsole.SetWindowTitle("Yate Status Monitor"); UpdateDisplay(); using (var resetEvent = new ManualResetEventSlim()) using (var client = new YateClient(Host, Port)) { Console.CancelKeyPress += (s, e) => { e.Cancel = true; resetEvent.Set(); }; client.Connect(RoleType.Global); client.Log($"start for {Environment.UserName}"); client.Watch("chan.startup", ChanUpdate); client.Watch("chan.hangup", ChanHangup); client.Watch("call.ringing", ChanUpdate); client.Watch("call.answered", ChanUpdate); client.Watch("chan.disconnected", ChanDisconnected); client.Watch("call.update", ChanUpdate); client.Watch("user.auth", UserAuth); client.Watch("user.register", UserRegister); client.Watch("user.unregister", UserUnregister); try { UpdateFromStatus(client); } catch (Exception ex) { FlashMessage("error", $"engine.status failed: {ex.Message}"); } resetEvent.Wait(); Cleanup(); } }
private void Cleanup() { VTConsole.EraseInDisplay(VTEraseMode.Entirely); VTConsole.SoftReset(); Console.WriteLine("bye."); }
private void WriteEmptyNotice() { VTConsole.WriteLine("no channel active", Color.Cyan); VTConsole.SetColorForeground(Color.White); }
private void UpdateDisplay() { WriteHeader(); if (ChannelData.Count == 0) { WriteEmptyNotice(); } foreach (var entry in ChannelData.OrderBy(x => x.Key)) { var id = entry.Key; var kv = entry.Value; string inout; switch (GetValueOrDefault(kv, "direction")) { case "incoming": inout = "-[in]->"; break; case "outgoing": inout = "<-[out]"; break; default: inout = "<-[?]->"; break; } var ystatus = GetValueOrDefault(kv, "ysm_status"); if (ystatus == "hungup" && GetValueOrDefault(kv, "status") != "answered") { ystatus = GetValueOrDefault(kv, "status"); } switch (ystatus) { case "rejected": VTConsole.SetColorForeground(Color.Yellow); VTConsole.SetColorBackground(Color.Red); break; case "ringing": VTConsole.SetColorForeground(Color.Yellow); VTConsole.SetColorBackground(Color.Black); break; case "answered": VTConsole.SetColorForeground(Color.Green); VTConsole.SetColorBackground(Color.Black); break; case "hungup": VTConsole.SetColorForeground(Color.White); VTConsole.SetColorBackground(Color.Blue); break; default: VTConsole.SetColorForeground(Color.White); VTConsole.SetColorBackground(Color.Black); break; } var status = ystatus; if (kv.ContainsKey("reason")) { status += ": " + kv["reason"]; } if (kv.ContainsKey("cause_sip")) { status += $" SIP {kv["cause_sip"]}/{GetValueOrDefault(kv, "reason_sip")}"; } Console.WriteLine($"{id,-10} {inout} {GetValueOrDefault(kv, "caller"),10} -> {GetValueOrDefault(kv, "called"),-10} | {GetValueOrDefault(kv, "address")} {status}"); VTConsole.EraseInLine(); } foreach (var value in FlashMessages.Values) { var level = value.Item1; var msg = value.Item2; switch (level) { case "info": VTConsole.SetColorForeground(Color.Yellow); VTConsole.SetColorBackground(Color.Black); break; case "notice": VTConsole.SetColorForeground(Color.Black); VTConsole.SetColorBackground(Color.Cyan); break; case "warning": VTConsole.SetColorForeground(Color.Black); VTConsole.SetColorBackground(Color.Red); break; case "error": VTConsole.SetColorForeground(Color.Red); VTConsole.SetColorBackground(Color.Black); break; default: VTConsole.SetColorForeground(Color.Cyan); VTConsole.SetColorBackground(Color.Black); break; } Console.WriteLine($"[{level}] {msg}"); } }
private static void RandomColorsForever() { VTConsole.CursorSetBlinking(false); VTConsole.CursorSetVisibility(true); VTConsole.SetColorBackground(Color.Black); VTConsole.SetColorForeground(Color.White); Console.Clear(); Console.SetCursorPosition(5, 8); VTConsole.Write("Hi there", Color.FromArgb(0, 255, 0)); Console.SetCursorPosition(0, 0); int r = 0; int g = 0; int b = 0; //for (var column = 0; column < Console.BufferWidth; column++) while (!Console.KeyAvailable) { // Set column to random and row to 0 var randomColumn = new Random().Next(0, Console.BufferWidth); Console.SetCursorPosition(randomColumn, 0); for (var row = 0; row < Console.WindowHeight - 1; row++) { // Always move the cursor down VTConsole.CursorMoveDown(); var percentageChance = new Random().Next(100); //if (percentageChance == 50) //{ // VTConsole.CursorPosition(new Random().Next(1, Console.WindowHeight), new Random().Next(1, Console.WindowWidth - 1)); // var datetimeString = DateTime.Now.ToString("hh:mm:ss"); // VTConsole.Write(datetimeString, Color.Black); // VTConsole.CursorMoveLeft(datetimeString.Length); //} // Randomly print a new block colour if (percentageChance < 40) { var random = new Random(); r = random.Next(255); g = random.Next(255); b = random.Next(255); // Values will only ever be slightly over 255 if (r > 255) { r -= 255; } if (g > 255) { g -= 255; } if (b > 255) { b -= 255; } // Vibrant colours only //bool vibrantColours = true; //if (vibrantColours) //{ // // Make the lowest value = 0 // if (r < g && r < b) // r = 0; // else if (g < r && g < b) // g = 0; // else if (b < g && b < r) // b = 0; //} //Debug.WriteLine($"r:{r} g:{g} b:{b}"); // vertical strip dark at the top VTConsole.Write(" ", Color.Black, Color.FromArgb(Convert.ToInt32(r / 1.5), Convert.ToInt32(g / 1.5), Convert.ToInt32(b / 1.5))); VTConsole.CursorMoveDown(); VTConsole.CursorMoveLeft(); VTConsole.Write(" ", Color.Black, Color.FromArgb(Convert.ToInt32(r / 1.2), Convert.ToInt32(g / 1.2), Convert.ToInt32(b / 1.2))); VTConsole.CursorMoveDown(); VTConsole.CursorMoveLeft(); VTConsole.Write(" ", Color.Black, Color.FromArgb(r, g, b)); VTConsole.CursorMoveLeft(); } else { VTConsole.Write(" ", Color.Black, Color.Black); VTConsole.CursorMoveDown(); VTConsole.CursorMoveLeft(); VTConsole.Write(" ", Color.Black, Color.Black); VTConsole.CursorMoveDown(); VTConsole.CursorMoveLeft(); VTConsole.Write(" ", Color.Black, Color.Black); VTConsole.CursorMoveLeft(); } //Thread.Sleep(5); } } }
static void Main(string[] args) { if (!VTConsole.IsSupported) { return; } VTConsole.Enable(); Console.OutputEncoding = Encoding.UTF8; Console.WriteLine("https://github.com/009342/ConsoleVideoPlayer"); if (args.Length == 0) { return; } //video : music bool isSound = true; VideoFileReader vfr = new VideoFileReader(); WaveOut waveOut = new WaveOut(); if (args.Length == 2) { size = int.Parse(args[1]); } audioFileReader = new AudioFileReader(args[0]); MediaFoundationReader video = null; try { Console.WriteLine("오디오 정보"); Console.WriteLine("인코딩 : " + audioFileReader.WaveFormat.ToString()); Console.WriteLine("샘플레이트 : " + audioFileReader.WaveFormat.SampleRate); Console.WriteLine("채널 : " + audioFileReader.WaveFormat.Channels); Console.WriteLine("길이 :" + audioFileReader.Length); } catch (Exception e) { isSound = false; Console.WriteLine("소리를 재생할 수 없습니다."); Console.WriteLine("오류 : " + e.ToString()); } vfr.Open(args[0]); double fps = (double)vfr.FrameRateNum / (double)vfr.FrameRateDen; fps = (fps > 59) ? 30 : fps; Console.WriteLine("비디오 정보"); Console.WriteLine("코덱 정보 : " + vfr.CodecName); Console.WriteLine("초당 프레임 : " + fps.ToString()); Console.WriteLine("총 프레임 : " + vfr.FrameCount); Console.WriteLine("너비 : " + vfr.Width); Console.WriteLine("높이 : " + vfr.Height); int Count = 5; while (Count-- > 0) { Console.WriteLine(Count.ToString()); Thread.Sleep(1000); } Console.Clear(); int c_width = 189; int c_height = 50; Console.SetWindowSize( Math.Min(c_width, Console.LargestWindowWidth), Console.LargestWindowHeight); int v_width = vfr.Width; int v_height = vfr.Height; int b_width = v_width / c_width; int b_height = v_height / c_height; if (isSound) { waveOut.Init(audioFileReader); } if (isSound) { waveOut.Play(); } Bitmap bm = new Bitmap(vfr.Width, vfr.Height); Random random = new Random(); Thread videoDecoderThread = new Thread(() => { VideoDecoderThread(vfr, fps); }); Thread frameDisposerThread = new Thread(() => { FrameDisposerThread(vfr); }); videoDecoderThread.Start(); frameDisposerThread.Start(); bool EOF = false; int tempIndex = 0; for (; ;) { while (Frames.Count < (int)((audioFileReader.CurrentTime.TotalMilliseconds / 1000) * fps) + healthy) { if (vfr.CurrentFrame + 1 == vfr.FrameCount) { EOF = true; break; } Thread.Sleep(10); Console.Title = "패스 : " + vfr.CurrentFrame.ToString() + "/" + ((audioFileReader.CurrentTime.TotalMilliseconds / 1000) * fps).ToString(); } if (EOF) { break; } tempIndex = (int)((audioFileReader.CurrentTime.TotalMilliseconds / 1000) * fps); bm = Frames[tempIndex]; if (bm == null) { break; } Console.Title = "현재 프레임 : " + vfr.CurrentFrame.ToString() + " 제거된 프레임 : " + disposedFrame + " 시간 : " + ((audioFileReader.CurrentTime.TotalMilliseconds / 1000)).ToString() + "초당 프레임 : " + fps.ToString(); Console.SetCursorPosition(0, 0); //Console.Title = "콘솔 출력중..."; ConsoleWriteImage2(bm); //Console.Title = "콘솔 출력 완료..."; SetCurrentFrame(tempIndex); } vfr.Close(); if (isSound) { video.Close(); } videoDecoderThread.Abort(); frameDisposerThread.Abort(); }