Giter Site home page Giter Site logo

cli-browser's Introduction

CLI-Browser

A small web browser that renders on command-line interface.

中文版

Introduction

This is a small web browser written in Vanilla JS (its runtime is Node.js, no external dependency).
It includes: HTTP Library, HTML Parser, CSS Parser, Layout Engine, Rendering Engine.
But the most special thing is that it renders the page on command-line interface.

How it works

  1. Get HTML content via HTTP protocol. (HttpRequest.js, ResponseParser.js, ResponseBodyParser.js)
  2. Parse HTML, build DOM tree. (HtmlParser.js)
  3. Parse and match CSS, build DOM with CSS. (CssParser.js, CssComputer.js)
  4. Layout, build DOM with position. (Layouter.js)
  5. Rendering and Drawing. (Render.js)

In particular, the page is rendered on CLI, how it works ?
Rendering means converting DOM tree into a bitmap (bitmap, is a two-dimensional table created in memory, saving each pixel).
Drawing means the process of drawing a bitmap to the visible screen.

In short, how do we display a bunch of pixels on CLI?
The answer is ANSI escape code (it can control each character color on CLI),
so I use a colored square whitespace character (\u3000) to represent a pixel,
In the end, the page is rendered as a bunch of colored square whitespace characters.

Usage

  1. git clone https://github.com/devlzl/CLI-Browser.git
  2. cd CLI-Browser
  3. Run node test/server.js, there are 27 test cases in the /test directory.
  4. You can first see how test cases look in a real browser. For example, visiting http://127.0.0.1:8000/24 in chrome to see the content of test24.html.
  5. Then open another new CLI (iTerm2 is recommended), press "command -" several times to shrink its font, then drag its window to make it bigger (characters as pixels should be as small as possible, window should be as large as possible to display more "pixels"). Then run node src/_main.js 127.0.0.1:8000/24 to see the content of test24.html in CLI !

Screenshot

on Google Chrome:

on iTerm2:

cli-browser's People

Contributors

devlzl avatar

Stargazers

Vadim Boev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.