Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text Overlays in local terminal #115

Open
EMUNES opened this issue Aug 21, 2022 · 0 comments
Open

Text Overlays in local terminal #115

EMUNES opened this issue Aug 21, 2022 · 0 comments
Assignees

Comments

@EMUNES
Copy link

EMUNES commented Aug 21, 2022

This is a really awesome plugin that offers a lot of convenience! I find one issue when I use it though. I try to use local terminal based on flutter_pty to build a local terminal on linux. I find that the terminal always overlap previous texts in the same line after certain lengths of characters.

For example, if I try to run conda activate, it will display as follow:

Screenshot from 2022-08-21 12-06-30

The command will run correctly if I type right, but the terminal display could always be like above, which is confusing. So I think this is something related to terminal frontend?

Another interesting feature of this problem is that: The larger the terminal window is, the more characters it can bear without overlapping the current line, but if you type more, there will still be overlapping.

Here is my code:

import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_pty/flutter_pty.dart';
import 'package:xterm/flutter.dart';
import 'package:xterm/xterm.dart';

class LocalTerminalBackend extends TerminalBackend {
  LocalTerminalBackend();

  final pty = Pty.start("bash");

  @override
  Future<int> get exitCode => pty.exitCode;

  @override
  void init() {
    pty.resize(20, 100);
  }

  @override
  Stream<String> get out =>
      pty.output.map((event) => String.fromCharCodes(event));

  @override
  void resize(int width, int height, int pixelWidth, int pixelHeight) {
    pty.resize(width, height);
  }

  @override
  void write(String input) {
    pty.write(Uint8List.fromList(input.codeUnits));
  }

  @override
  void terminate() {
    // client.disconnect('terminate');
  }

  @override
  void ackProcessed() {
    // NOOP
  }
}

class LocalTerminal extends StatefulWidget {
  const LocalTerminal({Key? key}) : super(key: key);

  @override
  _LocalTerminalState createState() => _LocalTerminalState();
}

class _LocalTerminalState extends State<LocalTerminal> {
  final terminal = Terminal(maxLines: 10000, backend: LocalTerminalBackend());

  @override
  void initState() {
    super.initState();
  }

  void onInput(String input) {
    print('input: $input');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: TerminalView(
          terminal: terminal,
        ),
      ),
    );
  }
}

It's basically the linux local example based on flutter_pty.

More information:

  • Platform: linux pop-os 22.04 LTS
  • Flutter Version: 3.0.5
  • Xterm Version: 2.6
  • Flutter_pty Version: 0.3

Thanks for viewing, It's a great project and I hope it will be better.

@xtyxtyx xtyxtyx self-assigned this Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants