晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
| DIR:/lib/python3.9/site-packages/glances/outputs/ |
| Current File : //lib/python3.9/site-packages/glances/outputs/glances_sparklines.py |
# -*- coding: utf-8 -*-
#
# This file is part of Glances.
#
# SPDX-FileCopyrightText: 2022 Nicolas Hennion <nicolas@nicolargo.com>
#
# SPDX-License-Identifier: LGPL-3.0-only
#
"""Manage sparklines for Glances output."""
from __future__ import unicode_literals
from __future__ import division
import sys
from glances.logger import logger
from glances.compat import nativestr
sparklines_module = True
try:
from sparklines import sparklines
except ImportError as e:
logger.warning("Sparklines module not found ({})".format(e))
sparklines_module = False
try:
'┌┬┐╔╦╗╒╤╕╓╥╖│║─═├┼┤╠╬╣╞╪╡╟╫╢└┴┘╚╩╝╘╧╛╙╨╜'.encode(sys.stdout.encoding)
except (UnicodeEncodeError, TypeError) as e:
logger.warning("UTF-8 is mandatory for sparklines ({})".format(e))
sparklines_module = False
class Sparkline(object):
"""Manage sparklines (see https://pypi.org/project/sparklines/)."""
def __init__(self, size, pre_char='[', post_char=']', empty_char=' ', with_text=True):
# If the sparklines python module available ?
self.__available = sparklines_module
# Sparkline size
self.__size = size
# Sparkline current percents list
self.__percent = []
# Char used for the decoration
self.__pre_char = pre_char
self.__post_char = post_char
self.__empty_char = empty_char
self.__with_text = with_text
@property
def available(self):
return self.__available
@property
def size(self, with_decoration=False):
# Return the sparkline size, with or without decoration
if with_decoration:
return self.__size
if self.__with_text:
return self.__size - 6
@property
def percents(self):
return self.__percent
@percents.setter
def percents(self, value):
self.__percent = value
@property
def pre_char(self):
return self.__pre_char
@property
def post_char(self):
return self.__post_char
def get(self):
"""Return the sparkline."""
ret = sparklines(self.percents, minimum=0, maximum=100)[0]
if self.__with_text:
percents_without_none = [x for x in self.percents if x is not None]
if len(percents_without_none) > 0:
ret = '{}{:5.1f}%'.format(ret, percents_without_none[-1])
return nativestr(ret)
def __str__(self):
"""Return the sparkline."""
return self.get()
|