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

feat: Add link ansi wrapper #462

Closed
1 task
Luckey-Elijah opened this issue Jul 18, 2022 · 3 comments · Fixed by #517
Closed
1 task

feat: Add link ansi wrapper #462

Luckey-Elijah opened this issue Jul 18, 2022 · 3 comments · Fixed by #517
Assignees
Labels
enhancement New feature or request

Comments

@Luckey-Elijah
Copy link
Contributor

Description

Add an ANSI wrapper that enables hyperlinks/links in the terminal. More info at this Gist on how to achieve the desired effect.

I've done this in one of my projects, but I think it might server others as well.

Requirements

  • API to "wrap" a string with a link for stdout.

Additional Context

An example API:

Future<void> main() async {
  Logger(level: Level.verbose).info(
    linkWrap(
      'You can find issues here',
      'https://github.com/felangel/mason/issues/',
    ),
  );
}
String linkWrap(String message, String link) {
  final uri = '\x1B]8;;$link\x1B\\';
  final text = '$message\x1B]8;;\x1B\\';
  return '$uri$text';
}

hyperlink

@Luckey-Elijah Luckey-Elijah changed the title feat(logger): Add link ansi wrapper feat: Add link ansi wrapper Jul 18, 2022
@felangel felangel added the enhancement New feature or request label Jul 20, 2022
@Luckey-Elijah
Copy link
Contributor Author

@felangel would you accept a PR for this feature? If so, feel free to assign to me

@felangel
Copy link
Owner

@felangel would you accept a PR for this feature? If so, feel free to assign to me

Yes, I'd love to add this 👍

@Luckey-Elijah
Copy link
Contributor Author

Luckey-Elijah commented Sep 14, 2022

I don't think using AnsiCode will work with it's wrap method since it doesn't take a second parameter for something like a "link".

I like to propose a top-level function link, a method on the Logger, or a new class for this (similar to AnsiCode).

The top-level function link or a link method on Logger would make the most sense. A new class just for wrapping a message with link is a bit overkill.

// "wraps" given string with a link, then returns the value
String linkWrap(String message, Uri uri) { ... }

void main() {
  final logger = Logger(level: Level.verbose);
  final issuesLink = linkWrap(
    'see issues here',
    Uri.parse('https://github.com/felangel/mason/issues/'),
  );
  logger
    ..info(issuesLink)
    ..warn(issuesLink)
    ..err(issuesLink);
}
class Logger {
  void link(
    String message,
    Uri uri, [
    void Function(String)? write,  // uses [info] by default
  ]) { ... }
}

void main() {
  final logger = Logger(level: Level.verbose);
  final issuesUri = Uri.parse('https://github.com/felangel/mason/issues/');
  logger
    ..link('see issues here', issuesUri)
    ..link('see issues here', issuesUri, logger.err)
    ..link('see issues here', issuesUri, logger.warn);
}

Woth implementations would be identical in output:

Screen Shot 2022-09-14 at 2 02 12 PM

Personally I like Logger.link interface the most

alestiago pushed a commit to alestiago/mason that referenced this issue Jun 9, 2023
…#462)

Bumps [eslint](https://github.com/eslint/eslint) from 8.30.0 to 8.31.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](eslint/eslint@v8.30.0...v8.31.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants