{"id":13447502,"url":"https://github.com/ivanseidel/node-draftlog","last_synced_at":"2025-05-15T02:09:00.681Z","repository":{"id":18375732,"uuid":"84117006","full_name":"ivanseidel/node-draftlog","owner":"ivanseidel","description":"📜 Create mutable log lines into the terminal, and give life to your logs!","archived":false,"fork":false,"pushed_at":"2023-04-28T14:21:29.000Z","size":2273,"stargazers_count":1250,"open_issues_count":7,"forks_count":33,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-05-07T23:08:44.484Z","etag":null,"topics":["ansi-escape-codes","console","logging","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ivanseidel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-03-06T20:21:09.000Z","updated_at":"2025-05-04T19:20:47.000Z","dependencies_parsed_at":"2022-08-07T09:00:40.952Z","dependency_job_id":"add4a289-a977-4256-bea3-1ff42c330e26","html_url":"https://github.com/ivanseidel/node-draftlog","commit_stats":{"total_commits":39,"total_committers":4,"mean_commits":9.75,"dds":0.07692307692307687,"last_synced_commit":"11cbd37034b2234ee4013f30356f901dc5e3968d"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanseidel%2Fnode-draftlog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanseidel%2Fnode-draftlog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanseidel%2Fnode-draftlog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanseidel%2Fnode-draftlog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ivanseidel","download_url":"https://codeload.github.com/ivanseidel/node-draftlog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254131340,"owners_count":22019922,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansi-escape-codes","console","logging","nodejs"],"created_at":"2024-07-31T05:01:19.486Z","updated_at":"2025-05-15T02:09:00.658Z","avatar_url":"https://github.com/ivanseidel.png","language":"JavaScript","readme":"![DraftLog](midia/draftlog.png)\n\u003c!-- [![NPM][npm-image]][npm-url] --\u003e\n\n[![Build Status][build-status-image]][build-status-url] [![Dependency Status][dependencies-image]][dependencies-url]\n\nBecause Logging can be pretty and fun\n\n![DraftLog GIF](midia/draftlog.gif)\n\n[build-status-image]: https://img.shields.io/travis/ivanseidel/node-draftlog.svg\n[build-status-url]: http://travis-ci.org/ivanseidel/node-draftlog\n[dependencies-image]: https://gemnasium.com/badges/github.com/ivanseidel/node-draftlog.svg\n[dependencies-url]: https://gemnasium.com/github.com/ivanseidel/node-draftlog\n[npm-image]: https://nodei.co/npm/draftlog.png?downloads=true\u0026stars=true\n[npm-url]: https://nodei.co/npm/draftlog\n\n## Installation\n\n```\n$ npm install draftlog\n```\n\n## What it does\n\nIt allows you to re-write a line of your log after being written. Just like post 'updating'. \nThis is the building block for any dynamic element such as `progress bars`, `loading status`, \n`animations`, `checkboxes` and so on.\n\nIt does that by keeping track of the current lines of code written through the `stream`, and\nmoving the cursor up to the line of the `LogDraft` you created previously, and updating its content.\n\nLook in the examples folders to see how easy it is, to create anything. No strict and fixed\nwidgets are given to you. Instead, use your creativity with this tool to create anything you\nwant! Share the results later with an example ;)\n\nLooking for CUTE Unicode chars? Check out [Unicute](https://github.com/ivanseidel/unicute).\n\nHow the\n[HECK](http://ascii-table.com/ansi-escape-sequences-vt-100.php) is \n[that](https://en.wikipedia.org/wiki/ANSI_escape_code) even\n[possible](http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x361.html)?\n\n## Usage\n\n```javascript\n// Setup\nconst DraftLog = require('draftlog')\nDraftLog(console)\n\n// Or, in a single line:\nrequire('draftlog').into(console)\n\n// Account for manual line breaks with:\nrequire('draftlog').into(console).addLineListener(process.stdin)\n```\n\nTo create a updatable log, use the `draft` method injected into the provided `console`:\n\n```javascript\n// Create a Draft log\nvar update = console.draft('Hi, my name is')\n\n// You can call logs after it\nconsole.log('Something else')\n\n// Use the received callback to update it as many times as you want\nupdate('Hi, my name is Ivan!')\n```\n\nHere are some interesting examples:\n```javascript\n// Prints a clock incrementing one every second in the same line\nvar draft = console.draft()\nvar elapsed = 1\nsetInterval( () =\u003e {\n  draft('Elapsed', elapsed++, 'seconds')\n}, 1000)\n\nconsole.log('It doesn`t matter')\nconsole.log('How \\n many \\n lines \\n it uses')\n```\n\nOr maybe, to show an flow process?\n```javascript\nfunction someAsyncFunction(){ \n  var TAG = '[someAsyncFunction]'\n  var log = console.draft(TAG, 'init')\n\n  function a() {\n    setTimeout(() =\u003e {\n      log(TAG, 'calling b')\n      b()\n    }, 500)\n  }\n\n  function b() {\n    setTimeout(() =\u003e {\n      log(TAG, 'finished')\n    })\n  }\n}\n```\n\nYou can create your own progress bar, just like \"that\":\n\n```javascript\nrequire('draftlog').into(console)\n\n// Input progess goes from 0 to 100\nfunction ProgressBar(progress) {\n  // Make it 50 characters length\n  var units = Math.round(progress / 2)\n  return '[' + '='.repeat(units) + ' '.repeat(50 - units) + '] ' + progress + '%'\n}\n\nvar barLine = console.draft('Starting download...')\ndownloadFile(function (progress) {\n  barLine(ProgressBar(progress))\n})\n\n// Will show something like: (being updated in realtime)\n// [============================                      ] 56%\n```\n\n## Learn from examples!\n\nWe have a few of them ready for you to use! Take a look at [the examples folder](examples/).\nRemember to replace `require('../')` with `require('draftlog')`.\n\nAlso, install [`chalk`](https://github.com/chalk/chalk) to get colors on your terminal ;)\n\n## Important things to know\n\nBecause of the way Terminals are built, it is not possible to update a text outside the viewing area of the terminal.\n\nThat said, DraftLogs are setup to automagically be rewritten on a new line if they reach the end of the viewport.\nNote that, you can disable that behavior, by setting `DraftLog.defaults.canReWrite = false`\n\nAlso, if the NodeJS environment cannot detect the number of rows of your terminal automatically, it will use\nthe default height on `DraftLog.defaults.maximumLinesUp`. Modify that if needed.\n\nWhen using `into(console).addLineListener(process.stdin)`, your code will no longer exit\nautomatically, because the stream is being \"read\". To stop your own code, you can call\n`process.exit(0)` or pause the stream when you want with: `process.stdin.pause()`.\n\n## Discouragements\n\nThis library is awesome for development, `cli` tools and what ever you want to created, that is NOT an\noptimized \"slave\" server. Please, disable it passing `true` as a second parameter to the DraftLog initialization:\n\n```javascript\n// Disable Initialization (true = production; false = development)\nDraftLog(console, true)\n// Or, with one line require-init:\nrequire('draftlog').into(console, true)\n```\n\n### Creator\n[Ivan Seidel](https://github.com/ivanseidel)\n","funding_links":[],"categories":["JavaScript","nodejs","Packages","📦 Legacy \u0026 Inactive Projects"],"sub_categories":["Command-line utilities"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivanseidel%2Fnode-draftlog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fivanseidel%2Fnode-draftlog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivanseidel%2Fnode-draftlog/lists"}