HTML Viewer
html-viewer demonstrates the buffer-oriented path from HTML input to terminal output. It parses HTML, renders the
document into a growing CursorBuffer, and in interactive mode exposes the visible area through a manually managed
BufferView.
Use This Demo When You Need…
A support example for rendering HTML into terminal-native styled text.
A practical reference for
CursorBufferplusBufferViewdriven scrolling.A bridge between document rendering and ordinary buffer-based full-screen output.
Run the Demo
Start the demo from the build directory:
$ ./cmake-build-debug/demo-apps/html-viewer
$ ./cmake-build-debug/demo-apps/html-viewer --style=simple
The interactive viewer uses the arrow keys, PgUp and PgDn, Home and End for navigation, S to
change style presets, and Q to quit. The capture below shows the deterministic --print mode with the bundled
tea document at 80 columns.
Captured Output (80x25)
─▸◆ Tea and the Tea Plant ◆◂───────────────────────────────────────────────── Tea is at once a plant, a drink, a ritual, a commodity, and a language of hospitality. In many homes it appears so often that it almost escapes notice, yet its story is unusually rich. The leaves that become green tea, black tea, white tea, oolong, and many other styles all come from one remarkable evergreen species, Camellia sinensis. From mountain gardens wrapped in mist to busy city kitchens where kettles begin to sing, tea connects agriculture, craft, trade, memory, and daily comfort. Unlike many beverages that rely on blending several ingredients, true tea begins with a single raw material: the young leaf and bud of the tea plant. What changes from cup to cup is not the species itself so much as the place where it grows, the season in which it is plucked, and the care with which it is handled after harvest. A fresh, grassy infusion and a dark, malty breakfast tea may seem worlds apart, but they are close relatives in botanical terms. That simple fact is one reason tea invites both casual enjoyment and deep study. Tea is ordinary and extraordinary at the same time. It can be prepared in a hurry or contemplated for an afternoon. It belongs equally to the field and to the table. A newspaper may mention tea as a crop measured in tons, while a poem may treat it as a sign of patience, friendship, or solitude. Few plants have entered so many cultures so completely. A cup of tea is never only a drink. It is often a pause, an offering, a habit inherited from others, and a way of making time visible. -◆ The Plant Itself ◆-───────────────────────────────────────────────────── The tea plant is an evergreen shrub or small tree in the family Theaceae. In cultivation it is usually kept low by pruning so that workers can harvest the tender new growth by hand or by machine. Left unmanaged, however, it can grow much taller and take on a more tree-like form. Its leaves are glossy, somewhat leathery, and usually dark green, though the youngest shoots may be pale, silvery, or bright green depending on variety and season. Botanists commonly distinguish between two main forms that are especially important in cultivation: Camellia sinensis var. sinensis and Camellia sinensis var. assamica. The first is often associated with smaller leaves and cooler or higher conditions, while the second is known for larger leaves and vigorous growth in warmer regions. In practice, tea agriculture includes a great many local cultivars, hybrids, and selections shaped by centuries of observation and breeding. The plant thrives best where rainfall is generous, drainage is good, and temperatures are moderate. Many celebrated tea landscapes share certain visual qualities: slopes, clouds, filtered sunlight, and air that moves between heat and coolness through the day. These conditions do not merely keep the plant alive; they influence the chemistry of the leaves and thus the taste in the cup. -◆ Roots, Leaves, and Growth ◆-───────────────────────────────────────── The root system of the tea plant anchors it on hillsides that may be steep and difficult to work. Healthy roots draw water and minerals from the soil, helping the plant endure repeated plucking over many years. Above ground, the framework of branches supports a canopy that growers shape into a convenient picking surface, often called a plucking table. The youngest growth matters most. Tea makers prize the bud and the first one or two leaves because they are tender, aromatic, and rich in compounds that contribute to flavor, body, bitterness, sweetness, and fragrance. The phrase two leaves and a bud has become almost symbolic of fine plucking. Older leaves can still be used, but they often yield a coarser result. New growth arrives in flushes, and the timing of those flushes matters. A spring harvest may be delicate and lively, while a summer or monsoon harvest may be stronger, fuller, or less refined. The plant, in other words, does not produce a single unchanging material. It speaks differently across the seasons. -◆ Environment and Terroir ◆-─────────────────────────────────────────── Tea lovers often borrow the language of terroir. The term is useful, even if it should be used with care. Soil type, altitude, rainfall, shade, latitude, surrounding vegetation, and local craft traditions all influence the final character of tea. A high mountain tea may show piercing aroma and clean sweetness, while a tea from a lower, warmer plain may offer depth, weight, and briskness. Altitude is especially admired because slower growth can concentrate desirable qualities. Mist and cloud cover may reduce stress on the leaves and protect volatile aromas. Cool nights and warm days can encourage complexity. Yet there is no single ideal environment. Tea is adaptable, and greatness appears in many forms. Some of the most important natural factors include: • Rainfall that is regular but not waterlogging • Acidic soils with good structure • Moderate temperatures • Elevation and slope • Shade, cloud cover, and wind exposure -◆ From Leaf to Cup ◆-───────────────────────────────────────────────────── One of the most fascinating truths about tea is that dramatically different styles can arise from the same plant. The difference lies in processing. Freshly picked leaves begin to change almost at once. Their water content shifts, enzymes become active, cell walls break down, aromas evolve, and color deepens or remains bright depending on what the maker does next. Tea manufacture is therefore both agricultural and culinary. At the broadest level, producers control several variables: withering, heating, rolling, oxidation, shaping, and drying. Not every style uses each step in the same way, and the order may vary. A green tea is typically heated early to halt oxidation, preserving a fresh profile. A black tea is allowed to oxidize more fully, producing darker leaves and deeper, often fruitier or maltier flavors. Oolong occupies a wide and beautiful middle ground. -◆ Main Categories of True Tea ◆-─────────────────────────────────────── 1. White tea, made from young buds or lightly handled leaves, usually emphasizes subtle sweetness and delicacy. 2. Green tea, heated soon after plucking, often tastes fresh, vegetal, nutty, chestnut-like, marine, or floral depending on style. 3. Yellow tea, a rarer category, undergoes a gentle enclosed step that softens some of the greener notes. 4. Oolong tea, partly oxidized and highly diverse, can range from floral and creamy to roasted and mineral. 5. Black tea, more fully oxidized, is often brisk, fragrant, fruity, malty, or honeyed. 6. Dark tea, including post-fermented styles, can become earthy, mellow, woody, or surprisingly sweet with age. These categories are useful, but they are not prison walls. Between one tea and another there are countless local methods, family traditions, experimental techniques, and market conventions. Tea resists overly neat classification. -◆ How Tea Is Commonly Processed ◆-───────────────────────────────────── 1. Leaves are plucked, often by selecting the bud and the youngest leaves. 2. They may be spread out to lose moisture in a stage called withering. 3. The leaves are shaped, bruised, or rolled to encourage or control chemical change. 4. Heating may be applied to stop oxidation or roasting may be used later to develop flavor. 5. The tea is dried for stability and storage. 6. In some styles it is sorted, blended, scented, compressed, or aged. Even this orderly description hides the true complexity. A masterful tea maker reads texture by touch, scent by instinct, weather by experience, and timing by judgment. Small decisions made over minutes can change the character of the finished tea for months or years. The making of tea is often described as craft, but it is also interpretation. The leaf offers possibilities, and the maker chooses which of them to reveal. -◆ Where Tea Grows ◆-────────────────────────────────────────────────────── Tea is grown across a broad belt of the world, especially in Asia and parts of Africa, and also in smaller quantities elsewhere. China, India, Sri Lanka, Japan, Kenya, Taiwan, Nepal, Vietnam, and many other regions contribute their own histories and styles. Some areas are known for daily staple teas, others for celebrated high-grown lots, and others for experimental or artisanal production. Geography matters, but so do the people who cultivate and process the plant. The reputation of a region may be built over centuries through careful selection of cultivars, adaptation to local weather, and the passing down of knowledge that is rarely captured fully in manuals. Tea remains an agricultural product shaped by human hands at every stage. -◆ Examples of Famous Tea Regions ◆-──────────────────────────────────── • China ⁃ Known for extraordinary diversity across green, white, yellow, oolong, black, and dark teas ⁃ Home to many historically influential styles and production methods • India ⁃ Darjeeling, often associated with fragrant and muscatel teas ⁃ Assam, noted for bold, malty black teas ⁃ Nilgiri, known for bright and aromatic character • Japan ⁃ Famous especially for green teas such as sencha, gyokuro, and matcha ⁃ Strong traditions of shading, steaming, and careful seasonal production • Sri Lanka ⁃ Produces a wide range of black teas from low, mid, and high elevations ⁃ Often valued for brightness and clarity in the cup • East Africa ⁃ Includes major producing countries with important roles in global supply ⁃ Commonly associated with brisk teas used in blends and tea bags, though specialty production also exists -◆ Labor and Harvest ◆-───────────────────────────────────────────────── In many tea regions, plucking remains labor-intensive. Skilled workers move through rows of bushes and select suitable shoots with great speed and accuracy. The work is repetitive, seasonal, and often physically demanding. Tea is therefore not only a story of taste; it is also a story of labor, land ownership, wages, transport, weather risk, and market pressure. A fine tea may invite elegant language at the table, yet it begins with agricultural discipline. This fact deserves emphasis. The cup can feel light and graceful, but the system behind it is material, economic, and sometimes harsh. To speak seriously about tea is to remember both pleasure and production. -◆ Tea in History ◆-─────────────────────────────────────────────────────── Tea has a long and layered history. It began as a plant known for medicinal, culinary, and eventually social uses, and it grew into one of the world’s most significant traded goods. Over time tea influenced agriculture, taxation, empire, industrial labor, domestic custom, shipping routes, and even political unrest. What now seems like a familiar kitchen staple once moved through courts, monasteries, merchant networks, and colonial systems. Different cultures adopted tea in different ways. Some emphasized whisked preparations, some steeped loose leaves, some brewed strong infusions with milk or sugar, and some incorporated salt, butter, spices, or compressed tea cakes. The drink’s apparent simplicity hides its historical flexibility. -◆ A Brief Historical Outline ◆-──────────────────────────────────────── 1. Tea first became established as a valued plant and drink in East Asia. 2. Methods of cultivation, preparation, and appreciation developed over centuries. 3. Trade networks spread tea outward to neighboring regions and eventually to Europe and beyond. 4. Demand increased, encouraging plantation systems in new territories. 5. Tea became tied to imperial power, taxation, and mass consumption. 6. Modern tea culture diversified into both industrial and specialty markets. Every stage of this history left traces in language, etiquette, commerce, and taste. Even today, when someone adds milk, chooses a gaiwan, uses a teabag, or discusses first flush harvests, that choice echoes older routes of exchange and habit. -◆ Tea and Public Life ◆-─────────────────────────────────────────────── Tea entered not only households but public institutions. It shaped breaks during factory work, social routines in offices, forms of hospitality in villages, and ceremonies of welcome in urban homes. It could be a luxury, then a necessity, then something so common that its absence felt unusual. This social career is part of tea’s power. It is sometimes tempting to romanticize tea as a gentle and innocent beverage. Yet history suggests a more complicated view. Tea has been linked to exploitation as well as comfort, to coercive trade as well as intimate domestic kindness. Both truths belong to the record. ◆◂────────────────────────────────────────────────────────────────────────▸◆ -◆ Flavor, Aroma, and Sensation ◆-───────────────────────────────────────── Tea tasting is often described with a vocabulary borrowed from fruit, flowers, wood, grain, seaweed, smoke, honey, cream, citrus, spice, wet stone, cocoa, and dried hay. None of these terms means that such ingredients are necessarily present. Instead, they point to analogies that help the drinker describe aroma, taste, and texture. Tea is rich in subtle compounds, and the human mind reaches for comparison when subtlety exceeds ordinary language. Good tea is not merely a matter of strength. Some of the most memorable cups are quiet, transparent, and slow to unfold. Others are emphatic from the start, with robust bitterness, briskness, and structure that make them ideal for milk, sugar, or food. There is no universal standard that places delicacy above force or force above delicacy. The style should suit the leaf, the intention, and the moment. -◆ Common Tasting Dimensions ◆-───────────────────────────────────────── Aroma The scent perceived from dry leaf, warmed leaf, liquor, and empty cup. Body The weight or texture of the tea in the mouth, ranging from thin to full and coating. Briskness A lively, bright quality often associated with certain black teas and fresh infusions. Astringency A drying sensation caused by interactions between tea compounds and saliva. Sweetness Not always sugary sweetness, but often a gentle, returning softness after swallowing. Finish The aftertaste and lingering impression that remains once the tea has been drunk. Experienced drinkers also pay attention to temperature, pacing, and change across repeated infusions. A tea can open slowly, revealing notes that were hidden at first. In this sense, tea is less like a fixed object than a sequence of moments. -◆ Why Tea Can Taste So Different ◆-──────────────────────────────────── • Plant variety and cultivar • Season of harvest • Weather before plucking • Leaf standard and plucking skill • Processing choices • Storage conditions • Brewing method Even the water matters. Hard or soft water, hotter or cooler water, short infusions or long steeps, abundant leaf or restrained dosing: these factors can turn the same tea from harsh to graceful or from flat to vivid. Many disagreements about tea are in fact disagreements about preparation. ◆◂────────────────────────────────────────────────────────────────────────▸◆ -◆ How Tea Is Prepared ◆-────────────────────────────────────────────────── There is no single correct method for making tea. A large pot for a family breakfast, a tiny vessel for repeated infusions, powdered tea whisked in a bowl, and leaves simmered with milk and spices are all legitimate expressions of tea culture. What matters is that method and leaf suit one another. Still, a few general principles are useful. Delicate teas usually prefer cooler water and shorter steeping. More robust teas can tolerate, and often benefit from, hotter water. Too little leaf may produce a weak and dull cup; too much leaf or too much time may lead to excess bitterness. Yet these are not strict laws. Some drinkers deliberately seek intensity. -◆ A Simple Brewing Guide ◆-──────────────────────────────────────────── 1. Warm the vessel if desired. 2. Measure the tea according to the style and the volume of water. 3. Use fresh water brought to a suitable temperature. 4. Infuse for an appropriate length of time. 5. Taste and adjust the next infusion rather than assuming the first attempt is final. Repeated infusion is especially important in many traditions. Rather than expecting everything from the first pour, the drinker allows the tea to evolve over several rounds. Early infusions may be floral and high-toned, later ones deeper and sweeter. This unfolding sequence is one of tea’s quiet pleasures. -◆ Tea with Other Ingredients ◆-──────────────────────────────────────── Although true tea can stand alone, it also welcomes companionship. Milk can round bitterness and emphasize body. Sugar can make a strong tea comforting and immediate. Lemon can brighten some black teas but may clash with milk. Mint, ginger, spices, roasted grains, and herbs have all been used in various traditions, sometimes to extend tea, sometimes to transform it, and sometimes to create a new beverage entirely. It is useful to distinguish between true tea and herbal infusions. Chamomile, peppermint, rooibos, and many other drinks are often called tea in everyday language, but botanically they are different. That does not make them lesser; it simply means they belong to another category. -◆ Culture, Ceremony, and Everyday Life ◆-───────────────────────────────── Tea can be formal or informal. It can be served with exacting attention to vessel, temperature, gesture, and sequence, or it can be poured absentmindedly into a chipped mug while a conversation continues. Both modes matter. Ceremony preserves and concentrates meaning; everyday use diffuses tea into the fabric of ordinary life. In some settings tea signifies respect for guests. In others it marks a work break, a family gathering, or a solitary hour. It may accompany newspapers, mourning, bargaining, study, romance, reconciliation, or silence. A drink so simple in composition has become surprisingly precise in social function. -◆ Why Tea Endures ◆-─────────────────────────────────────────────────── • It offers stimulation without the force some people associate with coffee. • It can be economical or luxurious. • It suits both solitary reflection and company. • It rewards expertise but does not require it. • It can be adapted to climate, cuisine, and custom. Tea also endures because it fits human rhythms. It asks for boiling water, a vessel, and a few moments of waiting. That brief pause is often part of its appeal. In a hurried day, the act of steeping can become a modest form of order. -◆ Tea as Language ◆-─────────────────────────────────────────────────── To offer tea is often to say something without speech. It may mean stay a little longer, you are welcome here, or let us talk calmly. Refusing tea can also carry meaning, as can accepting it immediately. Across cultures, the beverage has become part of an unwritten vocabulary of conduct and relationship. Where words might be too abrupt, tea often enters first. It softens the room before the conversation begins. -◆ Health, Stimulation, and Moderation ◆-────────────────────────────────── Tea contains caffeine, though the exact amount varies with leaf type, cultivar, brewing style, and serving size. Many drinkers value tea for its clear and gentle alertness. Others are drawn to its warmth and routine rather than its stimulating effect. Tea also contains a range of plant compounds that have attracted scientific and popular interest, though claims about health are often simplified in advertisements and casual conversation. A sensible view is best. Tea can be part of a balanced life, but it is not magic. For some people it soothes digestion or provides a pleasant alternative to sweeter drinks. For others, too much strong tea may bring restlessness or discomfort. The right amount depends on the individual, the tea, and the time of day. Moderation is wiser than exaggeration. Tea deserves appreciation for what it reliably is: a cultivated plant made into a refined and versatile drink. That is already enough. -◆ Economy, Industry, and Modern Change ◆-───────────────────────────────── The modern tea world includes tiny farms, large estates, cooperatives, brokers, exporters, blenders, packers, online retailers, tea rooms, supermarkets, and collectors of rare lots. Tea may be sold in dusty bricks, vacuum-sealed foil, paper sacks, elegant tins, or humble bags strung with thread. Industrial efficiency and artisanal care now coexist, sometimes uneasily, in the same global market. Mechanization has increased output in some regions, while specialty demand has encouraged finer plucking and more transparent sourcing in others. Consumers who once bought tea largely by brand increasingly ask about cultivar, elevation, harvest date, oxidation level, roasting style, or farm. This curiosity can support quality and accountability, though it can also become fashion. As with wine, coffee, and chocolate, knowledge can deepen pleasure but also tempt people into performance. The best approach is perhaps the simplest one: learn enough to taste attentively, respect the people who grow and make the leaf, and remain open to surprise. Tea, after all, can humble experts as easily as it delights newcomers. ◆◂────────────────────────────────────────────────────────────────────────▸◆ -◆ Conclusion ◆-─────────────────────────────────────────────────────────── Tea begins with a living plant whose leaves respond to weather, soil, altitude, and care. It passes through the hands of growers and makers who guide those leaves into many forms. It enters homes, markets, temples, workshops, cafés, railway stations, and quiet rooms. It belongs to botany and history, to chemistry and custom, to labor and leisure. That breadth is what makes tea more than a beverage and the tea plant more than a crop. A long look at tea reveals a satisfying paradox. The subject is vast, but the experience is intimate. Whole regions and centuries stand behind a single cup, yet the cup itself asks for nothing grand: only attention, perhaps a little patience, and a willingness to taste carefully. In that modest encounter, the tea plant continues its old work of joining the natural world to human life. To study tea is to move from leaf to landscape, from landscape to history, and from history back to the quiet fact of a warm cup in the hand.
Features Demonstrated
HtmlRendererrendering directly into aCursorBuffer.BufferViewused as an explicit viewport over the rendered document.Header and footer painting with ordinary buffer drawing calls in interactive mode.
Manual scroll offset management and style switching.
A print mode that turns the same HTML pipeline into plain terminal history output.
Relevant Source Files
If you want to explore the implementation, start with demo/html-viewer/src/HtmlViewerApp.hpp and
demo/html-viewer/src/HtmlViewerApp.cpp.