TerminalTerminal is a text based user interface. Enter "date" to display the current date.

Terminal - 图1

Documentation

Import

  1. import {TerminalModule} from 'primeng/terminal';
  2.  

Getting Started

Commands are processed using observables via the TerminalService. Import this service into your component and subscribe to commandHandler to process commands by sending replies with sendResponse function.

  1. import {Component} from '@angular/core';
  2. import {TerminalService} from 'primeng/components/terminal/terminalservice';
  3. @Component({
  4. template: '<p-terminal welcomeMessage="Welcome to PrimeNG" prompt="primeng $"></p-terminal>',
  5. providers: [TerminalService]
  6. })
  7. export class TerminalDemo {
  8. constructor(private terminalService: TerminalService) {
  9. this.terminalService.commandHandler.subscribe(command => {
  10. let response = (command === 'date') ? new Date().toDateString() : 'Unknown command: ' + command;
  11. this.terminalService.sendResponse(response);
  12. });
  13. }
  14. }
  15.  

Properties

NameTypeDefaultDescription
welcomeMessagestringnullInitial text to display on terminal.
promptstringnullPrompt text for each command.
stylestringnullInline style of the component.
styleClassstringnullStyle class of the component.

Styling

Following is the list of structural style classes, for theming classes visit theming page.

NameElement
ui-terminalContainer element.
ui-terminal-contentContent of terminal.
ui-terminal-content-promptPrompt text.
ui-terminal-inputInput element to enter commands.

Dependencies

None.

Source

View on GitHub

  1. <p-terminal welcomeMessage="Welcome to PrimeNG" prompt="primeng $"></p-terminal>
  2.  
  1. import {Component} from '@angular/core';
  2. import {TerminalService} from 'primeng/components/terminal/terminalservice';
  3. import {Subscription} from 'rxjs/Subscription';
  4. @Component({
  5. templateUrl: './terminaldemo.html',
  6. providers: [TerminalService]
  7. })
  8. export class TerminalDemo {
  9. subscription: Subscription;
  10. constructor(private terminalService: TerminalService) {
  11. this.terminalService.commandHandler.subscribe(command => {
  12. let response = (command === 'date') ? new Date().toDateString() : 'Unknown command: ' + command;
  13. this.terminalService.sendResponse(response);
  14. });
  15. }
  16. ngOnDestroy() {
  17. if(this.subscription) {
  18. this.subscription.unsubscribe();
  19. }
  20. }
  21. }
  22.