如何在不清除屏幕的情况下多行刷新变量输出

时间:2019-05-19 06:40:06

标签: bash refresh file-monitoring

我正在尝试监视日志文件,然后显示特定请求调用的计数,输出将显示标题行,其中包含每个请求的名称“ PUT GET HEAD”,并在其下方显示每个节点的请求计数每行。 我需要刷新显示每1秒计数的变量的输出

以下代码的问题,脚本会继续删除前几行并转到屏幕顶部,而输出应该是固定的,只有请求数应该刷新

private List<String> spinnerItem;

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mainBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);

        spinnerItem = new ArrayList<>();
        setSpinner();
    }

public void displayCities(List<CityResponse.City> cities) {
        mainBinding.helloText.setText(cities.get(508).getNama());
        for (CityResponse.City city : cities) {
            Log.d(TAG, city.getNama());
            spinnerItem.add(city.getNama());
        }
    }

private void setSpinner(){
        ArrayAdapter<String> adapter = new ArrayAdapter<>(getApplicationContext(), android.R.layout.simple_spinner_item, spinnerItem);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        mainBinding.spinnerCity.setAdapter(adapter);
        mainBinding.spinnerCity.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                String citySelected = parent.getItemAtPosition(position).toString();
                Toast.makeText(parent.getContext(), "City : " + citySelected, Toast.LENGTH_LONG).show();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                Toast.makeText(CityActivity.this, "Not Selected", Toast.LENGTH_LONG).show();
            }
        });
    }

这是预期的输出:

节点PUT-HEAD-GET-删除  节点2 1849 2183 41387 0

node-3 5339 8534 40838 0

node-4 1829 2196 46503 0

预期输出:每1秒刷新一次数字时,显示的内容应与上面相同

1 个答案:

答案 0 :(得分:0)

我同意UtLox的观点,通常来说,ncurses是您的最佳选择。考虑到这一点,请看一下bashsimplecurses

Git repo

Tutorial

Basic example