Changeset f2d72128 for perlwrap.pm
- Timestamp:
- Jan 16, 2008, 2:59:06 AM (17 years ago)
- Branches:
- master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- ba2ca66, 61abb18
- Parents:
- ff13a6f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
perlwrap.pm
rb0c8011 rf2d72128 831 831 # newline plus four spaces and that thing. 832 832 $body =~ s/\n(.)/\n $1/g; 833 833 # Trim trailing newlines. 834 $body =~ s/\n*$//; 834 835 return " ".$body; 835 836 } 836 837 838 package BarnOwl::Style::OneLine; 839 ################################################################################ 840 # Branching point for various formatting functions in this style. 841 ################################################################################ 842 use constant BASE_FORMAT => '%s %-13.13s %-11.11s %-12.12s '; 843 sub format_message($) { 844 my $m = shift; 845 846 # if ( $m->is_zephyr ) { 847 # return format_zephyr($m); 848 # } 849 if ( $m->is_login ) { 850 return format_login($m); 851 } 852 elsif ( $m->is_ping) { 853 return format_ping($m); 854 } 855 elsif ( $m->is_admin || $m->is_loopback) { 856 return format_local($m); 857 } 858 else { 859 return format_chat($m); 860 } 861 } 862 863 BarnOwl::_create_style("oneline", "BarnOwl::Style::OneLine::format_message", "Formats for one-line-per-message"); 864 865 ################################################################################ 866 867 sub format_login($) { 868 my $m = shift; 869 return sprintf( 870 BASE_FORMAT, 871 '<', 872 $m->type, 873 uc( $m->login ), 874 $m->pretty_sender) 875 . ($m->login_extra ? "at ".$m->login_extra : ''); 876 } 877 878 sub format_ping($) { 879 my $m = shift; 880 return sprintf( 881 BASE_FORMAT, 882 '<', 883 $m->type, 884 'PING', 885 $m->pretty_sender) 886 } 887 888 sub format_chat($) 889 { 890 my $m = shift; 891 my $dir = lc($m->{direction}); 892 my $dirsym = '-'; 893 if ($dir eq 'in') { 894 $dirsym = '<'; 895 } 896 elsif ($dir eq 'out') { 897 $dirsym = '>'; 898 } 899 900 my $line; 901 if ($m->is_personal) { 902 $line= sprintf(BASE_FORMAT, 903 $dirsym, 904 $m->type, 905 '', 906 ($dir eq 'out' 907 ? $m->pretty_recipient 908 : $m->pretty_sender)); 909 } 910 else { 911 $line = sprintf(BASE_FORMAT, 912 $dirsym, 913 $m->context, 914 $m->subcontext, 915 ($dir eq 'out' 916 ? $m->pretty_recipient 917 : $m->pretty_sender)); 918 } 919 920 my $body = $m->{body}; 921 $body =~ tr/\n/ /; 922 $line .= $body; 923 $line = BarnOwl::Style::boldify($line) if ($m->is_personal && lc($m->direction) eq 'in'); 924 return $line; 925 } 926 927 # Format locally generated messages 928 sub format_local($) 929 { 930 my $m = shift; 931 my $type = uc($m->{type}); 932 my $line = sprintf(BASE_FORMAT, '<', $type, '', ''); 933 my $body = $m->{body}; 934 $body =~ tr/\n/ /; 935 return $line.$body; 936 } 837 937 838 938 package BarnOwl::Style;
Note: See TracChangeset
for help on using the changeset viewer.